12 import os |
12 import os |
13 |
13 |
14 from PyQt5.QtCore import pyqtSlot, Qt, QSize |
14 from PyQt5.QtCore import pyqtSlot, Qt, QSize |
15 from PyQt5.QtWidgets import QDialog, QListWidgetItem |
15 from PyQt5.QtWidgets import QDialog, QListWidgetItem |
16 |
16 |
17 from E5Gui import E5FileDialog, E5MessageBox |
17 from E5Gui import E5MessageBox |
|
18 from E5Gui.E5PathPicker import E5PathPickerModes |
18 |
19 |
19 from .Ui_BookmarksImportDialog import Ui_BookmarksImportDialog |
20 from .Ui_BookmarksImportDialog import Ui_BookmarksImportDialog |
20 |
21 |
21 from . import BookmarksImporters |
22 from . import BookmarksImporters |
22 |
23 |
23 import Utilities |
|
24 import Globals |
24 import Globals |
25 import UI.PixmapCache |
|
26 |
25 |
27 |
26 |
28 class BookmarksImportDialog(QDialog, Ui_BookmarksImportDialog): |
27 class BookmarksImportDialog(QDialog, Ui_BookmarksImportDialog): |
29 """ |
28 """ |
30 Class implementing a dialog for importing bookmarks from other sources. |
29 Class implementing a dialog for importing bookmarks from other sources. |
38 @param parent reference to the parent widget (QWidget) |
37 @param parent reference to the parent widget (QWidget) |
39 """ |
38 """ |
40 super(BookmarksImportDialog, self).__init__(parent) |
39 super(BookmarksImportDialog, self).__init__(parent) |
41 self.setupUi(self) |
40 self.setupUi(self) |
42 |
41 |
43 self.chooseButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
42 self.filePicker.setMode(E5PathPickerModes.OpenFileMode) |
44 |
43 |
45 self.sourcesList.setIconSize(QSize(48, 48)) |
44 self.sourcesList.setIconSize(QSize(48, 48)) |
46 for icon, displayText, idText in BookmarksImporters.getImporters(): |
45 for icon, displayText, idText in BookmarksImporters.getImporters(): |
47 itm = QListWidgetItem(icon, displayText, self.sourcesList) |
46 itm = QListWidgetItem(icon, displayText, self.sourcesList) |
48 itm.setData(self.SourcesListIdRole, idText) |
47 itm.setData(self.SourcesListIdRole, idText) |
62 """ |
61 """ |
63 if self.__currentPage == 0: |
62 if self.__currentPage == 0: |
64 self.nextButton.setEnabled( |
63 self.nextButton.setEnabled( |
65 len(self.sourcesList.selectedItems()) == 1) |
64 len(self.sourcesList.selectedItems()) == 1) |
66 elif self.__currentPage == 1: |
65 elif self.__currentPage == 1: |
67 self.nextButton.setEnabled(self.fileEdit.text() != "") |
66 self.nextButton.setEnabled(self.filePicker.text() != "") |
68 |
67 |
69 @pyqtSlot() |
68 @pyqtSlot() |
70 def on_sourcesList_itemSelectionChanged(self): |
69 def on_sourcesList_itemSelectionChanged(self): |
71 """ |
70 """ |
72 Private slot to handle changes of the selection of the import source. |
71 Private slot to handle changes of the selection of the import source. |
73 """ |
72 """ |
74 self.__enableNextButton() |
73 self.__enableNextButton() |
75 |
74 |
76 @pyqtSlot(str) |
75 @pyqtSlot(str) |
77 def on_fileEdit_textChanged(self, txt): |
76 def on_filePicker_textChanged(self, txt): |
78 """ |
77 """ |
79 Private slot handling changes of the file to import bookmarks from. |
78 Private slot handling changes of the file to import bookmarks form. |
80 |
79 |
81 @param txt text of the line edit (string) |
80 @param txt text of the line edit (string) |
82 """ |
81 """ |
83 self.__enableNextButton() |
82 self.__enableNextButton() |
84 |
|
85 @pyqtSlot() |
|
86 def on_chooseButton_clicked(self): |
|
87 """ |
|
88 Private slot to choose the bookmarks file or directory. |
|
89 """ |
|
90 if self.__selectedSource == "ie": |
|
91 path = E5FileDialog.getExistingDirectory( |
|
92 self, |
|
93 self.tr("Choose Directory ..."), |
|
94 self.__sourceDir, |
|
95 E5FileDialog.Options(E5FileDialog.Option(0))) |
|
96 else: |
|
97 if Globals.isMacPlatform(): |
|
98 filter = "*{0}".format(os.path.splitext(self.__sourceFile)[1]) |
|
99 else: |
|
100 filter = self.__sourceFile |
|
101 path = E5FileDialog.getOpenFileName( |
|
102 self, |
|
103 self.tr("Choose File ..."), |
|
104 self.__sourceDir, |
|
105 filter) |
|
106 |
|
107 if path: |
|
108 self.fileEdit.setText(Utilities.toNativeSeparators(path)) |
|
109 |
83 |
110 @pyqtSlot() |
84 @pyqtSlot() |
111 def on_nextButton_clicked(self): |
85 def on_nextButton_clicked(self): |
112 """ |
86 """ |
113 Private slot to switch to the next page. |
87 Private slot to switch to the next page. |
133 self.nextButton.setText(self.tr("Finish")) |
107 self.nextButton.setText(self.tr("Finish")) |
134 |
108 |
135 self.__currentPage += 1 |
109 self.__currentPage += 1 |
136 self.pagesWidget.setCurrentIndex(self.__currentPage) |
110 self.pagesWidget.setCurrentIndex(self.__currentPage) |
137 self.__enableNextButton() |
111 self.__enableNextButton() |
|
112 |
|
113 if self.__selectedSource == "ie": |
|
114 self.filePicker.setMode(E5PathPickerModes.DirectoryMode) |
|
115 else: |
|
116 self.filePicker.setMode(E5PathPickerModes.OpenFileMode) |
|
117 if Globals.isMacPlatform(): |
|
118 filter = "*{0}".format( |
|
119 os.path.splitext(self.__sourceFile)[1]) |
|
120 else: |
|
121 filter = self.__sourceFile |
|
122 self.filePicker.setFilters(filter) |
|
123 self.filePicker.setDefaultDirectory(self.__sourceDir) |
138 |
124 |
139 elif self.__currentPage == 1: |
125 elif self.__currentPage == 1: |
140 if self.fileEdit.text() == "": |
126 if self.filePicker.text() == "": |
141 return |
127 return |
142 |
128 |
143 importer = BookmarksImporters.getImporter(self.__selectedSource) |
129 importer = BookmarksImporters.getImporter(self.__selectedSource) |
144 importer.setPath(self.fileEdit.text()) |
130 importer.setPath(self.filePicker.text()) |
145 if importer.open(): |
131 if importer.open(): |
146 self.__topLevelBookmarkNode = importer.importedBookmarks() |
132 self.__topLevelBookmarkNode = importer.importedBookmarks() |
147 if importer.error(): |
133 if importer.error(): |
148 E5MessageBox.critical( |
134 E5MessageBox.critical( |
149 self, |
135 self, |