7 Module implementing a dialog to enter the archive data. |
7 Module implementing a dialog to enter the archive data. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, QFileInfo |
12 from PyQt5.QtCore import pyqtSlot |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
14 |
14 |
15 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter |
15 from E5Gui.E5PathPicker import E5PathPickerModes |
16 from E5Gui import E5FileDialog |
|
17 |
16 |
18 from .Ui_HgArchiveDialog import Ui_HgArchiveDialog |
17 from .Ui_HgArchiveDialog import Ui_HgArchiveDialog |
19 |
18 |
20 import Utilities |
19 import Utilities |
21 import UI.PixmapCache |
|
22 |
20 |
23 |
21 |
24 class HgArchiveDialog(QDialog, Ui_HgArchiveDialog): |
22 class HgArchiveDialog(QDialog, Ui_HgArchiveDialog): |
25 """ |
23 """ |
26 Class implementing a dialog to enter the archive data. |
24 Class implementing a dialog to enter the archive data. |
33 @param parent reference to the parent widget (QWidget) |
31 @param parent reference to the parent widget (QWidget) |
34 """ |
32 """ |
35 super(HgArchiveDialog, self).__init__(parent) |
33 super(HgArchiveDialog, self).__init__(parent) |
36 self.setupUi(self) |
34 self.setupUi(self) |
37 |
35 |
38 self.archiveButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
36 self.archivePicker.setMode( |
39 |
37 E5PathPickerModes.SaveFileEnsureExtensionMode) |
40 self.__archiveFileCompleter = E5FileCompleter() |
|
41 self.__archiveDirCompleter = E5DirCompleter() |
|
42 self.__activeCompleter = self.__archiveFileCompleter |
|
43 self.archiveEdit.setCompleter(self.__activeCompleter) |
|
44 self.__activeCompleter.model().setNameFilters([]) |
|
45 |
38 |
46 self.typeComboBox.addItem( |
39 self.typeComboBox.addItem( |
47 self.tr("Detect Automatically"), "") |
40 self.tr("Detect Automatically"), "") |
48 self.typeComboBox.addItem( |
41 self.typeComboBox.addItem( |
49 self.tr("Directory of Files"), "files") |
42 self.tr("Directory of Files"), "files") |
66 self.__windowsFileFilters = [ |
59 self.__windowsFileFilters = [ |
67 self.tr("Compressed ZIP-Archive (*.zip)"), |
60 self.tr("Compressed ZIP-Archive (*.zip)"), |
68 self.tr("Uncompressed ZIP-Archive (*.uzip)") |
61 self.tr("Uncompressed ZIP-Archive (*.uzip)") |
69 ] |
62 ] |
70 if Utilities.isWindowsPlatform(): |
63 if Utilities.isWindowsPlatform(): |
71 self.__fileFilters = ";;".join( |
64 fileFilters = ";;".join( |
72 self.__windowsFileFilters + self.__unixFileFilters) |
65 self.__windowsFileFilters + self.__unixFileFilters) |
73 else: |
66 else: |
74 self.__fileFilters = ";;".join( |
67 fileFilters = ";;".join( |
75 self.__unixFileFilters + self.__windowsFileFilters) |
68 self.__unixFileFilters + self.__windowsFileFilters) |
76 self.__fileFilters += ";;" + self.tr("All Files (*)") |
69 fileFilters += ";;" + self.tr("All Files (*)") |
|
70 |
|
71 self.archivePicker.setFilters(fileFilters) |
77 |
72 |
78 self.__typeFilters = { |
73 self.__typeFilters = { |
79 "tar": ["*.tar"], |
74 "tar": ["*.tar"], |
80 "tbz2": ["*.tar.bz2", "*.tbz2"], |
75 "tbz2": ["*.tar.bz2", "*.tbz2"], |
81 "tgz": ["*.tar.gz", "*.tgz"], |
76 "tgz": ["*.tar.gz", "*.tgz"], |
92 |
87 |
93 msh = self.minimumSizeHint() |
88 msh = self.minimumSizeHint() |
94 self.resize(max(self.width(), msh.width()), msh.height()) |
89 self.resize(max(self.width(), msh.width()), msh.height()) |
95 |
90 |
96 @pyqtSlot(str) |
91 @pyqtSlot(str) |
97 def on_archiveEdit_textChanged(self, archive): |
92 def on_archivePicker_textChanged(self, archive): |
98 """ |
93 """ |
99 Private slot to handle changes of the archive name. |
94 Private slot to handle changes of the archive name. |
100 |
95 |
101 @param archive name of the archive (string) |
96 @param archive name of the archive (string) |
102 """ |
97 """ |
103 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(archive != "") |
98 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(archive != "") |
104 |
|
105 @pyqtSlot() |
|
106 def on_archiveButton_clicked(self): |
|
107 """ |
|
108 Private slot to select the archive name via a file selection dialog. |
|
109 """ |
|
110 type_ = self.typeComboBox.itemData(self.typeComboBox.currentIndex()) |
|
111 |
|
112 archive = Utilities.fromNativeSeparators(self.archiveEdit.text()) |
|
113 if not archive: |
|
114 archive = self.__projectPath |
|
115 |
|
116 if type_ == "files": |
|
117 archive = E5FileDialog.getExistingDirectory( |
|
118 self, |
|
119 self.tr("Select Archive Directory"), |
|
120 archive, |
|
121 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
122 else: |
|
123 archive, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
|
124 self, |
|
125 self.tr("Select Archive File"), |
|
126 archive, |
|
127 self.__fileFilters, |
|
128 None, |
|
129 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
|
130 if archive: |
|
131 ext = QFileInfo(archive).suffix() |
|
132 if not ext: |
|
133 ex = selectedFilter.split("(*")[1].split(")")[0] |
|
134 if ex: |
|
135 archive += ex |
|
136 |
|
137 if archive: |
|
138 self.archiveEdit.setText(Utilities.toNativeSeparators(archive)) |
|
139 |
99 |
140 @pyqtSlot(int) |
100 @pyqtSlot(int) |
141 def on_typeComboBox_activated(self, index): |
101 def on_typeComboBox_activated(self, index): |
142 """ |
102 """ |
143 Private slot to react on changes of the selected archive type. |
103 Private slot to react on changes of the selected archive type. |
144 |
104 |
145 @param index index of the selected type (integer) |
105 @param index index of the selected type (integer) |
146 """ |
106 """ |
147 type_ = self.typeComboBox.itemData(index) |
107 type_ = self.typeComboBox.itemData(index) |
148 if type_ == "files": |
108 if type_ == "files": |
149 if self.__activeCompleter != self.__archiveDirCompleter: |
109 self.archivePicker.setMode(E5PathPickerModes.DirectoryMode) |
150 self.__activeCompleter = self.__archiveDirCompleter |
|
151 self.archiveEdit.setCompleter(self.__activeCompleter) |
|
152 else: |
110 else: |
153 if self.__activeCompleter != self.__archiveFileCompleter: |
111 self.archivePicker.setMode( |
154 self.__activeCompleter = self.__archiveFileCompleter |
112 E5PathPickerModes.SaveFileEnsureExtensionMode) |
155 self.archiveEdit.setCompleter(self.__activeCompleter) |
|
156 if type_ in self.__typeFilters: |
113 if type_ in self.__typeFilters: |
157 self.__activeCompleter.model().setNameFilters( |
114 self.archivePicker.setNameFilters( |
158 self.__typeFilters[type_]) |
115 self.__typeFilters[type_]) |
159 else: |
116 else: |
160 self.__activeCompleter.model().setNameFilters([]) |
117 self.archivePicker.setNameFilters([]) |
161 |
118 |
162 def getData(self): |
119 def getData(self): |
163 """ |
120 """ |
164 Public method to retrieve the data. |
121 Public method to retrieve the data. |
165 |
122 |
166 @return tuple giving the archive name (string), the archive type |
123 @return tuple giving the archive name (string), the archive type |
167 (string), the directory prefix 8string) and a flag indicating |
124 (string), the directory prefix 8string) and a flag indicating |
168 to recurse into subrepositories (boolean) |
125 to recurse into subrepositories (boolean) |
169 """ |
126 """ |
170 return ( |
127 return ( |
171 self.archiveEdit.text(), |
128 self.archivePicker.text(), |
172 self.typeComboBox.itemData(self.typeComboBox.currentIndex()), |
129 self.typeComboBox.itemData(self.typeComboBox.currentIndex()), |
173 self.prefixEdit.text(), |
130 self.prefixEdit.text(), |
174 self.subReposCheckBox.isChecked(), |
131 self.subReposCheckBox.isChecked(), |
175 ) |
132 ) |