|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2013 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the archive data. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from E5Gui.E5PathPicker import E5PathPickerModes |
|
16 |
|
17 from .Ui_HgArchiveDialog import Ui_HgArchiveDialog |
|
18 |
|
19 import Utilities |
|
20 |
|
21 |
|
22 class HgArchiveDialog(QDialog, Ui_HgArchiveDialog): |
|
23 """ |
|
24 Class implementing a dialog to enter the archive data. |
|
25 """ |
|
26 def __init__(self, vcs, parent=None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param vcs reference to the Mercurial object (Hg) |
|
31 @param parent reference to the parent widget (QWidget) |
|
32 """ |
|
33 super(HgArchiveDialog, self).__init__(parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.archivePicker.setMode( |
|
37 E5PathPickerModes.SaveFileEnsureExtensionMode) |
|
38 |
|
39 self.typeComboBox.addItem( |
|
40 self.tr("Detect Automatically"), "") |
|
41 self.typeComboBox.addItem( |
|
42 self.tr("Directory of Files"), "files") |
|
43 self.typeComboBox.addItem( |
|
44 self.tr("Uncompressed TAR-Archive"), "tar") |
|
45 self.typeComboBox.addItem( |
|
46 self.tr("Bzip2 compressed TAR-Archive"), "tbz2") |
|
47 self.typeComboBox.addItem( |
|
48 self.tr("Gzip compressed TAR-Archive"), "tgz") |
|
49 self.typeComboBox.addItem( |
|
50 self.tr("Uncompressed ZIP-Archive"), "uzip") |
|
51 self.typeComboBox.addItem( |
|
52 self.tr("Compressed ZIP-Archive"), "zip") |
|
53 |
|
54 self.__unixFileFilters = [ |
|
55 self.tr("Bzip2 compressed TAR-Archive (*.tar.bz2)"), |
|
56 self.tr("Gzip compressed TAR-Archive (*.tar.gz)"), |
|
57 self.tr("Uncompressed TAR-Archive (*.tar)"), |
|
58 ] |
|
59 self.__windowsFileFilters = [ |
|
60 self.tr("Compressed ZIP-Archive (*.zip)"), |
|
61 self.tr("Uncompressed ZIP-Archive (*.uzip)") |
|
62 ] |
|
63 if Utilities.isWindowsPlatform(): |
|
64 fileFilters = ";;".join( |
|
65 self.__windowsFileFilters + self.__unixFileFilters) |
|
66 else: |
|
67 fileFilters = ";;".join( |
|
68 self.__unixFileFilters + self.__windowsFileFilters) |
|
69 fileFilters += ";;" + self.tr("All Files (*)") |
|
70 |
|
71 self.archivePicker.setFilters(fileFilters) |
|
72 |
|
73 self.__typeFilters = { |
|
74 "tar": ["*.tar"], |
|
75 "tbz2": ["*.tar.bz2", "*.tbz2"], |
|
76 "tgz": ["*.tar.gz", "*.tgz"], |
|
77 "uzip": ["*.uzip", "*.zip"], |
|
78 "zip": ["*.zip"], |
|
79 } |
|
80 |
|
81 self.subReposCheckBox.setEnabled(vcs.hasSubrepositories()) |
|
82 |
|
83 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
84 |
|
85 self.__projectPath = \ |
|
86 vcs.getPlugin().getProjectHelper().getProject().getProjectPath() |
|
87 |
|
88 msh = self.minimumSizeHint() |
|
89 self.resize(max(self.width(), msh.width()), msh.height()) |
|
90 |
|
91 @pyqtSlot(str) |
|
92 def on_archivePicker_textChanged(self, archive): |
|
93 """ |
|
94 Private slot to handle changes of the archive name. |
|
95 |
|
96 @param archive name of the archive (string) |
|
97 """ |
|
98 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(archive != "") |
|
99 |
|
100 @pyqtSlot(int) |
|
101 def on_typeComboBox_activated(self, index): |
|
102 """ |
|
103 Private slot to react on changes of the selected archive type. |
|
104 |
|
105 @param index index of the selected type (integer) |
|
106 """ |
|
107 type_ = self.typeComboBox.itemData(index) |
|
108 if type_ == "files": |
|
109 self.archivePicker.setMode(E5PathPickerModes.DirectoryMode) |
|
110 else: |
|
111 self.archivePicker.setMode( |
|
112 E5PathPickerModes.SaveFileEnsureExtensionMode) |
|
113 if type_ in self.__typeFilters: |
|
114 self.archivePicker.setNameFilters( |
|
115 self.__typeFilters[type_]) |
|
116 else: |
|
117 self.archivePicker.setNameFilters([]) |
|
118 |
|
119 def getData(self): |
|
120 """ |
|
121 Public method to retrieve the data. |
|
122 |
|
123 @return tuple giving the archive name (string), the archive type |
|
124 (string), the directory prefix 8string) and a flag indicating |
|
125 to recurse into subrepositories (boolean) |
|
126 """ |
|
127 return ( |
|
128 self.archivePicker.text(), |
|
129 self.typeComboBox.itemData(self.typeComboBox.currentIndex()), |
|
130 self.prefixEdit.text(), |
|
131 self.subReposCheckBox.isChecked(), |
|
132 ) |