|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter data for the Mercurial import command. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, QDateTime |
|
11 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
12 |
|
13 from E5Gui import E5FileDialog |
|
14 from E5Gui.E5Completers import E5FileCompleter |
|
15 |
|
16 from .Ui_HgImportDialog import Ui_HgImportDialog |
|
17 |
|
18 import Utilities |
|
19 |
|
20 |
|
21 class HgImportDialog(QDialog, Ui_HgImportDialog): |
|
22 """ |
|
23 Class implementing a dialog to enter data for the Mercurial import command. |
|
24 """ |
|
25 def __init__(self, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent reference to the parent widget (QWidget) |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
35 |
|
36 self.__patchFileCompleter = E5FileCompleter(self.patchFileEdit) |
|
37 |
|
38 self.__initDateTime = QDateTime.currentDateTime() |
|
39 self.dateEdit.setDateTime(self.__initDateTime) |
|
40 |
|
41 def __updateOK(self): |
|
42 """ |
|
43 Private slot to update the OK button. |
|
44 """ |
|
45 enabled = True |
|
46 if self.patchFileEdit.text() == "": |
|
47 enabled = False |
|
48 |
|
49 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled) |
|
50 |
|
51 @pyqtSlot(str) |
|
52 def on_patchFileEdit_textChanged(self, txt): |
|
53 """ |
|
54 Private slot to react on changes of the patch file edit. |
|
55 |
|
56 @param txt contents of the line edit (string) |
|
57 """ |
|
58 self.__updateOK() |
|
59 |
|
60 @pyqtSlot() |
|
61 def on_patchFileButton_clicked(self): |
|
62 """ |
|
63 Private slot called by pressing the file selection button. |
|
64 """ |
|
65 fn = E5FileDialog.getOpenFileName( |
|
66 self, |
|
67 self.trUtf8("Select patch file"), |
|
68 self.patchFileEdit.text(), |
|
69 self.trUtf8("Patch Files (*.diff *.patch);;All Files (*)")) |
|
70 |
|
71 if fn: |
|
72 self.patchFileEdit.setText(Utilities.toNativeSeparators(fn)) |
|
73 |
|
74 def getParameters(self): |
|
75 """ |
|
76 Public method to retrieve the import data. |
|
77 |
|
78 @return tuple naming the patch file, a flag indicating to not commit, |
|
79 a commit message, a commit date, a commit user, a strip count and |
|
80 a flag indicating to enforce the import |
|
81 (string, boolean, string, string, string, integer, boolean) |
|
82 """ |
|
83 if self.dateEdit.dateTime() != self.__initDateTime: |
|
84 date = self.dateEdit.dateTime().toString("yyyy-MM-dd hh:mm") |
|
85 else: |
|
86 date = "" |
|
87 |
|
88 return (self.patchFileEdit.text(), self.noCommitCheckBox.isChecked(), |
|
89 self.messageEdit.toPlainText(), date, self.userEdit.text(), |
|
90 self.stripSpinBox.value(), self.forceCheckBox.isChecked()) |