|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the archive data. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, QFileInfo |
|
11 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
12 |
|
13 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter |
|
14 from E5Gui import E5FileDialog |
|
15 |
|
16 from .Ui_HgArchiveDialog import Ui_HgArchiveDialog |
|
17 |
|
18 import Utilities |
|
19 |
|
20 |
|
21 class HgArchiveDialog(QDialog, Ui_HgArchiveDialog): |
|
22 """ |
|
23 Class implementing a dialog to enter the archive data. |
|
24 """ |
|
25 def __init__(self, vcs, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param vcs reference to the Mercurial object (Hg) |
|
30 @param parent reference to the parent widget (QWidget) |
|
31 """ |
|
32 super().__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.__archiveFileCompleter = E5FileCompleter() |
|
36 self.__archiveDirCompleter = E5DirCompleter() |
|
37 self.__activeCompleter = self.__archiveFileCompleter |
|
38 self.archiveEdit.setCompleter(self.__activeCompleter) |
|
39 |
|
40 self.typeComboBox.addItem(self.trUtf8("Detect Automatically"), "") |
|
41 self.typeComboBox.addItem(self.trUtf8("Directory of Files"), "files") |
|
42 self.typeComboBox.addItem(self.trUtf8("Uncompressed TAR-Archive"), "tar") |
|
43 self.typeComboBox.addItem(self.trUtf8("Bzip2 compressed TAR-Archive"), "tbz2") |
|
44 self.typeComboBox.addItem(self.trUtf8("Gzip compressed TAR-Archive"), "tgz") |
|
45 self.typeComboBox.addItem(self.trUtf8("Uncompressed ZIP-Archive"), "uzip") |
|
46 self.typeComboBox.addItem(self.trUtf8("Compressed ZIP-Archive"), "zip") |
|
47 |
|
48 self.__unixFileFilters = [ |
|
49 self.trUtf8("Bzip2 compressed TAR-Archive (*.tar.bz2)"), |
|
50 self.trUtf8("Gzip compressed TAR-Archive (*.tar.gz)"), |
|
51 self.trUtf8("Uncompressed TAR-Archive (*.tar)"), |
|
52 ] |
|
53 self.__windowsFileFilters = [ |
|
54 self.trUtf8("Compressed ZIP-Archive (*.zip)"), |
|
55 self.trUtf8("Uncompressed ZIP-Archive (*.uzip)") |
|
56 ] |
|
57 if Utilities.isWindowsPlatform(): |
|
58 self.__fileFilters = ";;".join( |
|
59 self.__windowsFileFilters + self.__unixFileFilters) |
|
60 else: |
|
61 self.__fileFilters = ";;".join( |
|
62 self.__unixFileFilters + self.__windowsFileFilters) |
|
63 self.__fileFilters += ";;" + self.trUtf8("All Files (*)") |
|
64 |
|
65 self.subReposCheckBox.setEnabled(vcs.hasSubrepositories()) |
|
66 |
|
67 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
68 |
|
69 self.__projectPath = \ |
|
70 vcs.getPlugin().getProjectHelper().getProject().getProjectPath() |
|
71 |
|
72 @pyqtSlot(str) |
|
73 def on_archiveEdit_textChanged(self, archive): |
|
74 """ |
|
75 Private slot to handle changes of the archive name. |
|
76 """ |
|
77 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(archive != "") |
|
78 |
|
79 @pyqtSlot() |
|
80 def on_archiveButton_clicked(self): |
|
81 """ |
|
82 Private slot to select the archive name via a file selection dialog. |
|
83 """ |
|
84 type_ = self.typeComboBox.itemData(self.typeComboBox.currentIndex()) |
|
85 |
|
86 archive = Utilities.fromNativeSeparators(self.archiveEdit.text()) |
|
87 if not archive: |
|
88 archive = self.__projectPath |
|
89 |
|
90 if type_ == "files": |
|
91 archive = E5FileDialog.getExistingDirectory( |
|
92 self, |
|
93 self.trUtf8("Select Archive Directory"), |
|
94 archive, |
|
95 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
96 else: |
|
97 archive, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
|
98 self, |
|
99 self.trUtf8("Select Archive File"), |
|
100 archive, |
|
101 self.__fileFilters, |
|
102 None, |
|
103 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
|
104 if archive: |
|
105 ext = QFileInfo(archive).suffix() |
|
106 if not ext: |
|
107 ex = selectedFilter.split("(*")[1].split(")")[0] |
|
108 if ex: |
|
109 archive += ex |
|
110 |
|
111 if archive: |
|
112 self.archiveEdit.setText(Utilities.toNativeSeparators(archive)) |
|
113 |
|
114 @pyqtSlot(int) |
|
115 def on_typeComboBox_activated(self, index): |
|
116 """ |
|
117 Private slot to react on changes of the selected archive type. |
|
118 |
|
119 @param index index of the selected type (integer) |
|
120 """ |
|
121 type_ = self.typeComboBox.itemData(index) |
|
122 if type_ == "files": |
|
123 if self.__activeCompleter != self.__archiveDirCompleter: |
|
124 self.__activeCompleter = self.__archiveDirCompleter |
|
125 self.archiveEdit.setCompleter(self.__activeCompleter) |
|
126 else: |
|
127 # TODO: add name filter to completer based upon selected type |
|
128 if self.__activeCompleter != self.__archiveFileCompleter: |
|
129 self.__activeCompleter = self.__archiveFileCompleter |
|
130 self.archiveEdit.setCompleter(self.__activeCompleter) |
|
131 |
|
132 def getData(self): |
|
133 """ |
|
134 Public method to retrieve the data. |
|
135 |
|
136 @return tuple giving the archive name (string), the archive type (string), |
|
137 the directory prefix 8string) and a flag indicating to recurse into |
|
138 subrepositories (boolean) |
|
139 """ |
|
140 return ( |
|
141 self.archiveEdit.text(), |
|
142 self.typeComboBox.itemData(self.typeComboBox.currentIndex()), |
|
143 self.prefixEdit.text(), |
|
144 self.subReposCheckBox.isChecked(), |
|
145 ) |