45
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 ** Contact: Qt Software Information (qt-info@nokia.com)
|
|
5 **
|
|
6 ** This file is part of the demonstration applications of the Qt Toolkit.
|
|
7 **
|
|
8 ** $QT_BEGIN_LICENSE:LGPL$
|
|
9 ** Commercial Usage
|
|
10 ** Licensees holding valid Qt Commercial licenses may use this file in
|
|
11 ** accordance with the Qt Commercial License Agreement provided with the
|
|
12 ** Software or, alternatively, in accordance with the terms contained in
|
|
13 ** a written agreement between you and Nokia.
|
|
14 **
|
|
15 ** GNU Lesser General Public License Usage
|
|
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
17 ** General Public License version 2.1 as published by the Free Software
|
|
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
19 ** packaging of this file. Please review the following information to
|
|
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
22 **
|
|
23 ** In addition, as a special exception, Nokia gives you certain
|
|
24 ** additional rights. These rights are described in the Nokia Qt LGPL
|
|
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|
26 ** package.
|
|
27 **
|
|
28 ** GNU General Public License Usage
|
|
29 ** Alternatively, this file may be used under the terms of the GNU
|
|
30 ** General Public License version 3.0 as published by the Free Software
|
|
31 ** Foundation and appearing in the file LICENSE.GPL included in the
|
|
32 ** packaging of this file. Please review the following information to
|
|
33 ** ensure the GNU General Public License version 3.0 requirements will be
|
|
34 ** met: http://www.gnu.org/copyleft/gpl.html.
|
|
35 **
|
|
36 ** If you are unsure which license is appropriate for your use, please
|
|
37 ** contact the sales department at qt-sales@nokia.com.
|
|
38 ** $QT_END_LICENSE$
|
|
39 **
|
|
40 ****************************************************************************/
|
|
41
|
72
|
42 module bookmarks;
|
45
|
43
|
|
44
|
72
|
45 import qt.core.QObject;
|
|
46 import qt.core.QAbstractItemModel;
|
|
47
|
|
48 import qt.gui.QUndoCommand;
|
|
49
|
|
50 import qt.core.QBuffer;
|
|
51 import qt.core.QFile;
|
|
52 import qt.core.QMimeData;
|
|
53
|
|
54 import qt.gui.QDesktopServices;
|
|
55 import qt.gui.QDragEnterEvent;
|
|
56 import qt.gui.QFileDialog;
|
|
57 import qt.gui.QHeaderView;
|
|
58 import qt.gui.QIcon;
|
|
59 import qt.gui.QMessageBox;
|
|
60 import qt.gui.QToolButton;
|
|
61
|
|
62 import QtWebKit.QWebSettings;
|
|
63
|
|
64 import qt.core.QDebug;
|
|
65
|
45
|
66 import bookmarks;
|
|
67 import autosaver;
|
|
68 import browserapplication;
|
|
69 import history;
|
|
70 import xbel;
|
|
71
|
|
72
|
|
73 const char[] BOOKMARKBAR = "Bookmarks Bar";
|
|
74 const char[] BOOKMARKMENU = "Bookmarks Menu";
|
|
75
|
|
76
|
|
77 /*!
|
73
|
78 Bookmark manager, owner of the bookmarks, loads, saves and basic tasks
|
|
79 */
|
45
|
80 class BookmarksManager : public QObject
|
|
81 {
|
74
|
82 mixin Signal!("entryAdded", BookmarkNode /*item*/);
|
|
83 mixin Signal!("entryRemoved", BookmarkNode /*parent*/, int /*row*/, BookmarkNode /*item*/);
|
|
84 mixin Signal!("entryChanged", BookmarkNode /*item*/);
|
45
|
85
|
|
86 public:
|
73
|
87
|
|
88 this(QObject parent = null)
|
|
89 {
|
|
90 super(parent);
|
|
91 m_loaded = false;
|
|
92 m_saveTimer = new AutoSaver(this);
|
|
93 m_bookmarkRootNode = null;
|
|
94 m_bookmarkModel = null;
|
|
95 this.entryAdded.connect(&m_saveTimer.changeOccurred);
|
|
96 this.entryRemoved.connect(&m_saveTimer.changeOccurred);
|
|
97 this.entryChanged.connect(&m_saveTimer.changeOccurred);
|
|
98 }
|
45
|
99
|
73
|
100 ~this()
|
|
101 {
|
|
102 m_saveTimer.saveIfNeccessary();
|
|
103 }
|
45
|
104
|
73
|
105 void addBookmark(BookmarkNode parent, BookmarkNode node, int row = -1)
|
|
106 {
|
|
107 if (!m_loaded)
|
|
108 return;
|
|
109 assert(parent);
|
|
110 InsertBookmarksCommand command = new InsertBookmarksCommand(this, parent, node, row);
|
|
111 m_commands.push(command);
|
|
112 }
|
45
|
113
|
74
|
114 void removeBookmark(BookmarkNode node)
|
73
|
115 {
|
|
116 if (!m_loaded)
|
|
117 return;
|
|
118
|
|
119 assert(node);
|
|
120 BookmarkNode parent = node.parent();
|
|
121 int row = parent.children().indexOf(node);
|
|
122 RemoveBookmarksCommand command = new RemoveBookmarksCommand(this, parent, row);
|
|
123 m_commands.push(command);
|
|
124 }
|
|
125
|
74
|
126 void setTitle(BookmarkNode node, QString newTitle)
|
73
|
127 {
|
|
128 if (!m_loaded)
|
|
129 return;
|
|
130
|
|
131 assert(node);
|
|
132 ChangeBookmarkCommand command = new ChangeBookmarkCommand(this, node, newTitle, true);
|
|
133 m_commands.push(command);
|
|
134 }
|
45
|
135
|
74
|
136 void setUrl(BookmarkNode node, QString newUrl)
|
73
|
137 {
|
|
138 if (!m_loaded)
|
|
139 return;
|
45
|
140
|
73
|
141 assert(node);
|
|
142 ChangeBookmarkCommand command = new ChangeBookmarkCommand(this, node, newUrl, false);
|
|
143 m_commands.push(command);
|
|
144 }
|
45
|
145
|
73
|
146 void changeExpanded()
|
|
147 {
|
|
148 m_saveTimer.changeOccurred();
|
|
149 }
|
45
|
150
|
74
|
151 BookmarkNode bookmarks()
|
73
|
152 {
|
|
153 if (!m_loaded)
|
|
154 load();
|
|
155 return m_bookmarkRootNode;
|
|
156 }
|
45
|
157
|
74
|
158 BookmarkNode menu()
|
73
|
159 {
|
|
160 if (!m_loaded)
|
|
161 load();
|
45
|
162
|
73
|
163 for (int i = m_bookmarkRootNode.children().count() - 1; i >= 0; --i) {
|
|
164 BookmarkNode node = m_bookmarkRootNode.children().at(i);
|
|
165 if (node.title == tr(BOOKMARKMENU))
|
|
166 return node;
|
|
167 }
|
|
168 assert(false);
|
|
169 return 0;
|
|
170 }
|
45
|
171
|
74
|
172 BookmarkNode toolbar()
|
73
|
173 {
|
|
174 if (!m_loaded)
|
|
175 load();
|
45
|
176
|
73
|
177 for (int i = m_bookmarkRootNode.children().count() - 1; i >= 0; --i) {
|
|
178 BookmarkNode node = m_bookmarkRootNode.children().at(i);
|
|
179 if (node.title == tr(BOOKMARKBAR))
|
|
180 return node;
|
|
181 }
|
|
182 assert(false);
|
|
183 return 0;
|
|
184 }
|
45
|
185
|
73
|
186 BookmarksModel bookmarksModel()
|
|
187 {
|
|
188 if (!m_bookmarkModel)
|
|
189 m_bookmarkModel = new BookmarksModel(this, this);
|
|
190 return m_bookmarkModel;
|
|
191 }
|
45
|
192
|
73
|
193 QUndoStack undoRedoStack() { return m_commands; };
|
45
|
194
|
73
|
195 public:
|
|
196
|
|
197 void importBookmarks()
|
|
198 {
|
|
199 QString fileName = QFileDialog.getOpenFileName(0, tr("Open File"), QString(), tr("XBEL (*.xbel *.xml)"));
|
|
200 if (fileName.isEmpty())
|
|
201 return;
|
45
|
202
|
73
|
203 XbelReader reader;
|
|
204 BookmarkNode importRootNode = reader.read(fileName);
|
|
205 if (reader.error() != QXmlStreamReader.NoError) {
|
|
206 QMessageBox.warning(0, QLatin1String("Loading Bookmark"),
|
|
207 tr("Error when loading bookmarks on line %1, column %2:\n"
|
|
208 "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString()));
|
|
209 }
|
45
|
210
|
73
|
211 importRootNode.setType(BookmarkNode.Folder);
|
|
212 importRootNode.title = (tr("Imported %1").arg(QDate.currentDate().toString(Qt.SystemLocaleShortDate)));
|
|
213 addBookmark(menu(), importRootNode);
|
|
214 }
|
45
|
215
|
|
216
|
73
|
217 void exportBookmarks()
|
|
218 {
|
|
219 QString fileName = QFileDialog.getSaveFileName(0, tr("Save File"),
|
|
220 tr("%1 Bookmarks.xbel").arg(QCoreApplication.applicationName()),
|
|
221 tr("XBEL (*.xbel *.xml)"));
|
|
222 if (fileName.isEmpty())
|
|
223 return;
|
45
|
224
|
73
|
225 XbelWriter writer;
|
|
226 if (!writer.write(fileName, m_bookmarkRootNode))
|
|
227 QMessageBox.critical(0, tr("Export error"), tr("error saving bookmarks"));
|
|
228 }
|
45
|
229
|
73
|
230 private:
|
|
231
|
|
232 void save()
|
|
233 {
|
|
234 if (!m_loaded)
|
|
235 return;
|
45
|
236
|
73
|
237 XbelWriter writer;
|
|
238 QString dir = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
|
|
239 QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
|
|
240 if (!writer.write(bookmarkFile, m_bookmarkRootNode))
|
|
241 qWarning() << "BookmarkManager: error saving to" << bookmarkFile;
|
|
242 }
|
45
|
243
|
|
244 private:
|
73
|
245
|
|
246 void load()
|
|
247 {
|
|
248 if (m_loaded)
|
|
249 return;
|
|
250 m_loaded = true;
|
45
|
251
|
73
|
252 QString dir = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
|
|
253 QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
|
|
254 if (!QFile.exists(bookmarkFile))
|
|
255 bookmarkFile = QLatin1String(":defaultbookmarks.xbel");
|
45
|
256
|
73
|
257 XbelReader reader;
|
|
258 m_bookmarkRootNode = reader.read(bookmarkFile);
|
|
259 if (reader.error() != QXmlStreamReader.NoError) {
|
|
260 QMessageBox.warning(0, QLatin1String("Loading Bookmark"),
|
|
261 tr("Error when loading bookmarks on line %1, column %2:\n"
|
|
262 "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString()));
|
|
263 }
|
45
|
264
|
73
|
265 BookmarkNode toolbar = null;
|
|
266 BookmarkNode menu = null;
|
74
|
267 BookmarkNode[] others;
|
73
|
268 for (int i = m_bookmarkRootNode.children().count() - 1; i >= 0; --i) {
|
|
269 BookmarkNode node = m_bookmarkRootNode.children().at(i);
|
|
270 if (node.type() == BookmarkNode.Folder) {
|
|
271 // Automatically convert
|
|
272 if (node.title == tr("Toolbar Bookmarks") && !toolbar) {
|
|
273 node.title = tr(BOOKMARKBAR);
|
|
274 }
|
|
275 if (node.title == tr(BOOKMARKBAR) && !toolbar) {
|
|
276 toolbar = node;
|
|
277 }
|
45
|
278
|
73
|
279 // Automatically convert
|
|
280 if (node.title == tr("Menu") && !menu) {
|
|
281 node.title = tr(BOOKMARKMENU);
|
|
282 }
|
|
283 if (node.title == tr(BOOKMARKMENU) && !menu) {
|
|
284 menu = node;
|
|
285 }
|
|
286 } else {
|
|
287 others.append(node);
|
|
288 }
|
|
289 m_bookmarkRootNode.remove(node);
|
|
290 }
|
|
291 assert(m_bookmarkRootNode.children().count() == 0);
|
|
292 if (!toolbar) {
|
|
293 toolbar = new BookmarkNode(BookmarkNode.Folder, m_bookmarkRootNode);
|
|
294 toolbar.title = tr(BOOKMARKBAR);
|
|
295 } else {
|
|
296 m_bookmarkRootNode.add(toolbar);
|
|
297 }
|
45
|
298
|
73
|
299 if (!menu) {
|
|
300 menu = new BookmarkNode(BookmarkNode.Folder, m_bookmarkRootNode);
|
|
301 menu.title = tr(BOOKMARKMENU);
|
|
302 } else {
|
|
303 m_bookmarkRootNode.add(menu);
|
|
304 }
|
45
|
305
|
73
|
306 for (int i = 0; i < others.count(); ++i)
|
|
307 menu.add(others.at(i));
|
|
308 }
|
45
|
309
|
73
|
310 bool m_loaded;
|
|
311 AutoSaver m_saveTimer;
|
|
312 BookmarkNode m_bookmarkRootNode;
|
|
313 BookmarksModel m_bookmarkModel;
|
|
314 QUndoStack m_commands;
|
72
|
315 }
|
45
|
316
|
|
317 class RemoveBookmarksCommand : public QUndoCommand
|
|
318 {
|
73
|
319 public:
|
45
|
320
|
73
|
321 this(BookmarksManager m_bookmarkManagaer, BookmarkNode parent, int row)
|
|
322 {
|
74
|
323 super(BookmarksManager.tr("Remove Bookmark"));
|
73
|
324 m_row = row;
|
|
325 m_bookmarkManagaer = m_bookmarkManagaer;
|
|
326 m_node = parent.children().value(row);
|
|
327 m_parent = parent;
|
|
328 m_done = false;
|
|
329 }
|
45
|
330
|
73
|
331 ~this()
|
|
332 {
|
|
333 if (m_done && !m_node.parent()) {
|
|
334 delete m_node;
|
|
335 }
|
|
336 }
|
45
|
337
|
73
|
338 void undo()
|
|
339 {
|
|
340 m_parent.add(m_node, m_row);
|
74
|
341 m_bookmarkManagaer.entryAdded.emit(m_node);
|
73
|
342 m_done = false;
|
|
343 }
|
45
|
344
|
73
|
345 void redo()
|
|
346 {
|
|
347 m_parent.remove(m_node);
|
74
|
348 m_bookmarkManagaer.entryRemoved.emit(m_parent, m_row, m_node);
|
73
|
349 m_done = true;
|
|
350 }
|
45
|
351
|
|
352 protected:
|
73
|
353
|
|
354 int m_row;
|
|
355 BookmarksManager m_bookmarkManagaer;
|
|
356 BookmarkNode m_node;
|
|
357 BookmarkNode m_parent;
|
|
358 bool m_done;
|
|
359 }
|
45
|
360
|
|
361 class InsertBookmarksCommand : public RemoveBookmarksCommand
|
|
362 {
|
73
|
363 public:
|
|
364 this(BookmarksManager m_bookmarkManagaer, BookmarkNode parent, BookmarkNode node, int row)
|
|
365 {
|
|
366 super(m_bookmarkManagaer, parent, row);
|
45
|
367
|
73
|
368 setText(BookmarksManager.tr("Insert Bookmark"));
|
|
369 m_node = node;
|
|
370 }
|
45
|
371
|
73
|
372 void undo() { RemoveBookmarksCommand.redo(); }
|
|
373 void redo() { RemoveBookmarksCommand.undo(); }
|
45
|
374 }
|
|
375
|
|
376 class ChangeBookmarkCommand : public QUndoCommand
|
|
377 {
|
73
|
378 public:
|
45
|
379
|
73
|
380 this(BookmarksManager m_bookmarkManagaer, BookmarkNode node, QString newValue, bool title)
|
|
381 {
|
|
382 super();
|
|
383 m_bookmarkManagaer = m_bookmarkManagaer;
|
|
384 m_title = title;
|
|
385 m_newValue = newValue;
|
|
386 m_node = node;
|
|
387 if (m_title) {
|
|
388 m_oldValue = m_node.title;
|
|
389 setText(BookmarksManager.tr("Name Change"));
|
|
390 } else {
|
|
391 m_oldValue = m_node.url;
|
|
392 setText(BookmarksManager.tr("Address Change"));
|
|
393 }
|
|
394 }
|
45
|
395
|
73
|
396 void undo()
|
|
397 {
|
|
398 if (m_title)
|
|
399 m_node.title = m_oldValue;
|
|
400 else
|
|
401 m_node.url = m_oldValue;
|
74
|
402 m_bookmarkManagaer.entryChanged.emit(m_node);
|
73
|
403 }
|
45
|
404
|
73
|
405 void redo()
|
|
406 {
|
|
407 if (m_title)
|
|
408 m_node.title = m_newValue;
|
|
409 else
|
|
410 m_node.url = m_newValue;
|
74
|
411 m_bookmarkManagaer.entryChanged.emit(m_node);
|
73
|
412 }
|
45
|
413
|
|
414 private:
|
73
|
415
|
|
416 BookmarksManager m_bookmarkManagaer;
|
|
417 bool m_title;
|
|
418 QString m_oldValue;
|
|
419 QString m_newValue;
|
|
420 BookmarkNode m_node;
|
45
|
421 }
|
|
422
|
|
423 /*!
|
73
|
424 BookmarksModel is a QAbstractItemModel wrapper around the BookmarkManager
|
|
425 */
|
72
|
426 import qt.gui.QIcon;
|
|
427
|
45
|
428 class BookmarksModel : public QAbstractItemModel
|
|
429 {
|
73
|
430 public:
|
45
|
431
|
73
|
432 void entryAdded(BookmarkNode item)
|
|
433 {
|
|
434 assert(item && item.parent());
|
|
435 int row = item.parent().children().indexOf(item);
|
|
436 BookmarkNode parent = item.parent();
|
|
437 // item was already added so remove beore beginInsertRows is called
|
|
438 parent.remove(item);
|
|
439 beginInsertRows(index(parent), row, row);
|
|
440 parent.add(item, row);
|
|
441 endInsertRows();
|
|
442 }
|
45
|
443
|
74
|
444 void entryRemoved(BookmarkNode parent, int row, BookmarkNode item)
|
73
|
445 {
|
|
446 // item was already removed, re-add so beginRemoveRows works
|
|
447 parent.add(item, row);
|
|
448 beginRemoveRows(index(parent), row, row);
|
|
449 parent.remove(item);
|
|
450 endRemoveRows();
|
|
451 }
|
45
|
452
|
74
|
453 void entryChanged(BookmarkNode item)
|
73
|
454 {
|
|
455 QModelIndex idx = index(item);
|
74
|
456 dataChanged.emit(idx, idx);
|
73
|
457 }
|
|
458
|
45
|
459 public:
|
73
|
460
|
|
461 enum Roles {
|
|
462 TypeRole = Qt.UserRole + 1,
|
|
463 UrlRole = Qt.UserRole + 2,
|
|
464 UrlStringRole = Qt.UserRole + 3,
|
|
465 SeparatorRole = Qt.UserRole + 4
|
74
|
466 };
|
45
|
467
|
74
|
468 this(BookmarksManager bookmarkManager, QObject parent = null)
|
73
|
469 {
|
74
|
470 super(parent);
|
73
|
471 m_endMacro = false;
|
|
472 m_bookmarksManager = bookmarkManager;
|
|
473 bookmarkManager.entryAdded.connect(&this.entryAdded);
|
|
474 bookmarkManager.entryRemoved.connect(&this.entryRemoved);
|
|
475 bookmarkManager.entryChanged.connect(&this.entryChanged);
|
|
476 }
|
45
|
477
|
74
|
478 BookmarksManager bookmarksManager()
|
|
479 {
|
|
480 return m_bookmarksManager;
|
|
481 }
|
45
|
482
|
74
|
483 QVariant headerData(int section, Qt.Orientation orientation, int role = Qt.DisplayRole)
|
73
|
484 {
|
|
485 if (orientation == Qt.Horizontal && role == Qt.DisplayRole) {
|
|
486 switch (section) {
|
|
487 case 0: return tr("Title");
|
|
488 case 1: return tr("Address");
|
|
489 }
|
|
490 }
|
|
491 return QAbstractItemModel.headerData(section, orientation, role);
|
|
492 }
|
45
|
493
|
73
|
494 QVariant data(QModelIndex index, int role = Qt.DisplayRole)
|
|
495 {
|
|
496 if (!index.isValid() || index.model() != this)
|
|
497 return QVariant();
|
45
|
498
|
73
|
499 BookmarkNode bookmarkNode = node(index);
|
|
500 switch (role) {
|
|
501 case Qt.EditRole:
|
|
502 case Qt.DisplayRole:
|
|
503 if (bookmarkNode.type() == BookmarkNode.Separator) {
|
|
504 switch (index.column()) {
|
|
505 case 0: return QString(50, 0xB7);
|
|
506 case 1: return QString();
|
|
507 }
|
|
508 }
|
45
|
509
|
73
|
510 switch (index.column()) {
|
|
511 case 0: return bookmarkNode.title;
|
|
512 case 1: return bookmarkNode.url;
|
|
513 }
|
|
514 break;
|
|
515 case BookmarksModel.UrlRole:
|
|
516 return QUrl(bookmarkNode.url);
|
|
517 break;
|
|
518 case BookmarksModel.UrlStringRole:
|
|
519 return bookmarkNode.url;
|
|
520 break;
|
|
521 case BookmarksModel.TypeRole:
|
|
522 return bookmarkNode.type();
|
|
523 break;
|
|
524 case BookmarksModel.SeparatorRole:
|
|
525 return (bookmarkNode.type() == BookmarkNode.Separator);
|
|
526 break;
|
|
527 case Qt.DecorationRole:
|
|
528 if (index.column() == 0) {
|
|
529 if (bookmarkNode.type() == BookmarkNode.Folder)
|
|
530 return QApplication.style().standardIcon(QStyle.SP_DirIcon);
|
|
531 return BrowserApplication.instance().icon(bookmarkNode.url);
|
|
532 }
|
|
533 }
|
45
|
534
|
73
|
535 return QVariant();
|
|
536 }
|
|
537
|
|
538 int columnCount(QModelIndex parent = QModelIndex())
|
|
539 {
|
|
540 return (parent.column() > 0) ? 0 : 2;
|
|
541 }
|
|
542
|
|
543 int rowCount(QModelIndex parent = QModelIndex())
|
|
544 {
|
|
545 if (parent.column() > 0)
|
|
546 return 0;
|
45
|
547
|
73
|
548 if (!parent.isValid())
|
|
549 return m_bookmarksManager.bookmarks().children().count();
|
45
|
550
|
74
|
551 BookmarkNode item = cast(BookmarkNode) parent.internalPointer();
|
73
|
552 return item.children().count();
|
|
553 }
|
|
554
|
74
|
555 QModelIndex index(int row, int column, QModelIndex parent = QModelIndex())
|
73
|
556 {
|
|
557 if (row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent))
|
|
558 return QModelIndex();
|
45
|
559
|
73
|
560 // get the parent node
|
|
561 BookmarkNode parentNode = node(parent);
|
|
562 return createIndex(row, column, parentNode.children().at(row));
|
|
563 }
|
45
|
564
|
74
|
565 QModelIndex parent(QModelIndex index = QModelIndex())
|
73
|
566 {
|
|
567 if (!index.isValid())
|
|
568 return QModelIndex();
|
45
|
569
|
73
|
570 BookmarkNode itemNode = node(index);
|
|
571 BookmarkNode parentNode = (itemNode ? itemNode.parent() : 0);
|
|
572 if (!parentNode || parentNode == m_bookmarksManager.bookmarks())
|
|
573 return QModelIndex();
|
45
|
574
|
73
|
575 // get the parent's row
|
|
576 BookmarkNode grandParentNode = parentNode.parent();
|
|
577 int parentRow = grandParentNode.children().indexOf(parentNode);
|
|
578 assert(parentRow >= 0);
|
|
579 return createIndex(parentRow, 0, parentNode);
|
|
580 }
|
45
|
581
|
73
|
582 Qt.ItemFlags flags(QModelIndex index)
|
|
583 {
|
|
584 if (!index.isValid())
|
|
585 return Qt.NoItemFlags;
|
|
586
|
|
587 Qt.ItemFlags flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled;
|
45
|
588
|
73
|
589 BookmarkNode bookmarkNode = node(index);
|
45
|
590
|
73
|
591 if (bookmarkNode != m_bookmarksManager.menu() && bookmarkNode != m_bookmarksManager.toolbar()) {
|
|
592 flags |= Qt.ItemIsDragEnabled;
|
|
593 if (bookmarkNode.type() != BookmarkNode.Separator)
|
|
594 flags |= Qt.ItemIsEditable;
|
|
595 }
|
|
596 if (hasChildren(index))
|
|
597 flags |= Qt.ItemIsDropEnabled;
|
|
598 return flags;
|
|
599 }
|
|
600
|
74
|
601 Qt.DropActions supportedDropActions()
|
73
|
602 {
|
|
603 return Qt.CopyAction | Qt.MoveAction;
|
|
604 }
|
45
|
605
|
74
|
606 bool removeRows(int row, int count, QModelIndex parent = QModelIndex())
|
73
|
607 {
|
|
608 if (row < 0 || count <= 0 || row + count > rowCount(parent))
|
|
609 return false;
|
|
610
|
|
611 BookmarkNode bookmarkNode = node(parent);
|
|
612 for (int i = row + count - 1; i >= row; --i) {
|
|
613 BookmarkNode node = bookmarkNode.children().at(i);
|
|
614 if (node == m_bookmarksManager.menu() || node == m_bookmarksManager.toolbar())
|
|
615 continue;
|
45
|
616
|
73
|
617 m_bookmarksManager.removeBookmark(node);
|
|
618 }
|
|
619 if (m_endMacro) {
|
|
620 m_bookmarksManager.undoRedoStack().endMacro();
|
|
621 m_endMacro = false;
|
|
622 }
|
|
623 return true;
|
|
624 }
|
|
625
|
|
626 bool setData(QModelIndex index, QVariant value, int role = Qt.EditRole)
|
|
627 {
|
|
628 if (!index.isValid() || (flags(index) & Qt.ItemIsEditable) == 0)
|
|
629 return false;
|
45
|
630
|
73
|
631 BookmarkNode item = node(index);
|
45
|
632
|
73
|
633 switch (role) {
|
|
634 case Qt.EditRole:
|
|
635 case Qt.DisplayRole:
|
|
636 if (index.column() == 0) {
|
|
637 m_bookmarksManager.setTitle(item, value.toString());
|
|
638 break;
|
|
639 }
|
|
640 if (index.column() == 1) {
|
|
641 m_bookmarksManager.setUrl(item, value.toString());
|
|
642 break;
|
|
643 }
|
|
644 return false;
|
|
645 case BookmarksModel.UrlRole:
|
|
646 m_bookmarksManager.setUrl(item, value.toUrl().toString());
|
|
647 break;
|
|
648 case BookmarksModel.UrlStringRole:
|
|
649 m_bookmarksManager.setUrl(item, value.toString());
|
|
650 break;
|
|
651 default:
|
|
652 break;
|
|
653 return false;
|
|
654 }
|
|
655
|
|
656 return true;
|
|
657 }
|
45
|
658
|
74
|
659 QMimeData mimeData(QModelIndexList indexes)
|
73
|
660 {
|
|
661 QMimeData mimeData = new QMimeData();
|
|
662 QByteArray data;
|
|
663 auto stream = new QDataStream(&data, QIODevice.WriteOnly);
|
74
|
664 foreach (QModelIndex index; indexes) {
|
73
|
665 if (index.column() != 0 || !index.isValid())
|
|
666 continue;
|
|
667 QByteArray encodedData;
|
|
668 auto buffer = new QBuffer(&encodedData);
|
|
669 buffer.open(QBuffer.ReadWrite);
|
|
670 XbelWriter writer;
|
|
671 const BookmarkNode parentNode = node(index);
|
|
672 writer.write(&buffer, parentNode);
|
|
673 stream << encodedData;
|
|
674 }
|
|
675 mimeData.setData(MIMETYPE, data);
|
|
676 return mimeData;
|
|
677 }
|
45
|
678
|
74
|
679 const char[] MIMETYPE = QLatin1String("application/bookmarks.xbel");
|
45
|
680
|
73
|
681 QStringList mimeTypes()
|
|
682 {
|
|
683 QStringList types;
|
|
684 types << MIMETYPE;
|
|
685 return types;
|
|
686 }
|
45
|
687
|
73
|
688 bool dropMimeData(QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
|
|
689 {
|
|
690 if (action == Qt.IgnoreAction)
|
|
691 return true;
|
45
|
692
|
73
|
693 if (!data.hasFormat(MIMETYPE) || column > 0)
|
|
694 return false;
|
45
|
695
|
73
|
696 QByteArray ba = data.data(MIMETYPE);
|
74
|
697 QDataStream stream = new QDataStream(&ba, QIODevice.ReadOnly);
|
73
|
698 if (stream.atEnd())
|
|
699 return false;
|
45
|
700
|
73
|
701 QUndoStack undoStack = m_bookmarksManager.undoRedoStack();
|
|
702 undoStack.beginMacro(QLatin1String("Move Bookmarks"));
|
45
|
703
|
73
|
704 while (!stream.atEnd()) {
|
|
705 QByteArray encodedData;
|
|
706 stream >> encodedData;
|
74
|
707 QBuffer buffer = new QBuffer(&encodedData);
|
73
|
708 buffer.open(QBuffer.ReadOnly);
|
45
|
709
|
73
|
710 XbelReader reader;
|
|
711 BookmarkNode rootNode = reader.read(&buffer);
|
74
|
712 BookmarkNode[] children = rootNode.children();
|
73
|
713 for (int i = 0; i < children.count(); ++i) {
|
|
714 BookmarkNode bookmarkNode = children.at(i);
|
|
715 rootNode.remove(bookmarkNode);
|
|
716 row = qMax(0, row);
|
|
717 BookmarkNode parentNode = node(parent);
|
|
718 m_bookmarksManager.addBookmark(parentNode, bookmarkNode, row);
|
|
719 m_endMacro = true;
|
|
720 }
|
|
721 delete rootNode;
|
|
722 }
|
|
723 return true;
|
|
724 }
|
45
|
725
|
73
|
726 bool hasChildren(QModelIndex parent = QModelIndex())
|
|
727 {
|
|
728 if (!parent.isValid())
|
|
729 return true;
|
|
730 const BookmarkNode parentNode = node(parent);
|
|
731 return (parentNode.type() == BookmarkNode.Folder);
|
|
732 }
|
45
|
733
|
73
|
734 BookmarkNode node(QModelIndex index)
|
|
735 {
|
74
|
736 BookmarkNode itemNode = cast(BookmarkNode) index.internalPointer();
|
73
|
737 if (!itemNode)
|
|
738 return m_bookmarksManager.bookmarks();
|
|
739 return itemNode;
|
|
740 }
|
45
|
741
|
73
|
742 QModelIndex index(BookmarkNode node)
|
|
743 {
|
|
744 BookmarkNode parent = node.parent();
|
|
745 if (!parent)
|
|
746 return QModelIndex();
|
|
747 return createIndex(parent.children().indexOf(node), 0, node);
|
|
748 }
|
45
|
749
|
|
750 private:
|
|
751
|
73
|
752 bool m_endMacro;
|
|
753 BookmarksManager m_bookmarksManager;
|
45
|
754 }
|
|
755
|
|
756 // Menu that is dynamically populated from the bookmarks
|
|
757 import modelmenu;
|
73
|
758
|
45
|
759 class BookmarksMenu : public ModelMenu
|
|
760 {
|
74
|
761 mixin Signal!("openUrl", QUrl /*url*/);
|
45
|
762
|
|
763 public:
|
73
|
764
|
74
|
765 this(QWidget parent = null)
|
73
|
766 {
|
|
767 super(parent);
|
|
768 m_bookmarksManager = 0;
|
|
769 this.activated.connect(&this.activated);
|
|
770 setMaxRows(-1);
|
|
771 setHoverRole(BookmarksModel.UrlStringRole);
|
|
772 setSeparatorRole(BookmarksModel.SeparatorRole);
|
|
773 }
|
|
774
|
74
|
775 void setInitialActions(QAction[] actions)
|
73
|
776 {
|
|
777 m_initialActions = actions;
|
|
778 for (int i = 0; i < m_initialActions.count(); ++i)
|
|
779 addAction(m_initialActions.at(i));
|
|
780 }
|
|
781
|
45
|
782 protected:
|
73
|
783
|
45
|
784 bool prePopulated()
|
73
|
785 {
|
|
786 m_bookmarksManager = BrowserApplication.bookmarksManager();
|
|
787 setModel(m_bookmarksManager.bookmarksModel());
|
|
788 setRootIndex(m_bookmarksManager.bookmarksModel().index(1, 0));
|
|
789 // initial actions
|
|
790 for (int i = 0; i < m_initialActions.count(); ++i)
|
|
791 addAction(m_initialActions.at(i));
|
|
792 if (!m_initialActions.isEmpty())
|
|
793 addSeparator();
|
|
794 createMenu(model().index(0, 0), 1, this);
|
|
795 return true;
|
|
796 }
|
45
|
797
|
|
798 private:
|
73
|
799
|
|
800 void activated(QModelIndex index)
|
|
801 {
|
74
|
802 openUrl.emit(index.data(BookmarksModel.UrlRole).toUrl());
|
73
|
803 }
|
|
804
|
|
805 private:
|
|
806
|
|
807 BookmarksManager m_bookmarksManager;
|
74
|
808 QAction[] m_initialActions;
|
45
|
809 }
|
|
810
|
|
811 /*
|
|
812 Proxy model that filters out the bookmarks so only the folders
|
|
813 are left behind. Used in the add bookmark dialog combobox.
|
|
814 */
|
72
|
815 import qt.gui.QSortFilterProxyModel;
|
|
816
|
45
|
817 class AddBookmarkProxyModel : public QSortFilterProxyModel
|
|
818 {
|
|
819 public:
|
73
|
820
|
|
821 this(QObject parent = null)
|
|
822 {
|
|
823 super(parent);
|
|
824 }
|
|
825
|
|
826 int columnCount(QModelIndex parent = QModelIndex())
|
|
827 {
|
|
828 return qMin(1, QSortFilterProxyModel.columnCount(parent));
|
|
829 }
|
|
830
|
|
831 protected:
|
|
832
|
|
833 bool filterAcceptsRow(int source_row, QModelIndex source_parent)
|
|
834 {
|
|
835 QModelIndex idx = sourceModel().index(source_row, 0, source_parent);
|
|
836 return sourceModel().hasChildren(idx);
|
|
837 }
|
45
|
838 }
|
|
839
|
|
840 /*!
|
73
|
841 Add bookmark dialog
|
|
842 */
|
72
|
843
|
45
|
844 import ui_addbookmarkdialog;
|
72
|
845
|
45
|
846 class AddBookmarkDialog : public QDialog, public Ui_AddBookmarkDialog
|
|
847 {
|
73
|
848 public:
|
45
|
849
|
73
|
850 this(QString url, QString title, QWidget parent = null, BookmarksManager bookmarkManager = null)
|
74
|
851 //: QDialog(parent)
|
73
|
852 {
|
|
853 m_url = url;
|
|
854 m_bookmarksManager = bookmarkManager;
|
|
855
|
|
856 setWindowFlags(Qt.Sheet);
|
|
857 if (!m_bookmarksManager)
|
|
858 m_bookmarksManager = BrowserApplication.bookmarksManager();
|
|
859 setupUi(this);
|
|
860 QTreeView view = new QTreeView(this);
|
|
861 m_proxyModel = new AddBookmarkProxyModel(this);
|
|
862 BookmarksModel model = m_bookmarksManager.bookmarksModel();
|
|
863 m_proxyModel.setSourceModel(model);
|
|
864 view.setModel(m_proxyModel);
|
|
865 view.expandAll();
|
|
866 view.header().setStretchLastSection(true);
|
|
867 view.header().hide();
|
|
868 view.setItemsExpandable(false);
|
|
869 view.setRootIsDecorated(false);
|
|
870 view.setIndentation(10);
|
|
871 location.setModel(m_proxyModel);
|
|
872 view.show();
|
|
873 location.setView(view);
|
|
874 BookmarkNode menu = m_bookmarksManager.menu();
|
|
875 QModelIndex idx = m_proxyModel.mapFromSource(model.index(menu));
|
|
876 view.setCurrentIndex(idx);
|
|
877 location.setCurrentIndex(idx.row());
|
|
878 name.setText(title);
|
|
879 }
|
72
|
880
|
|
881 private:
|
45
|
882
|
73
|
883 void accept()
|
|
884 {
|
|
885 QModelIndex index = location.view().currentIndex();
|
|
886 index = m_proxyModel.mapToSource(index);
|
|
887 if (!index.isValid())
|
|
888 index = m_bookmarksManager.bookmarksModel().index(0, 0);
|
|
889 BookmarkNode parent = m_bookmarksManager.bookmarksModel().node(index);
|
|
890 BookmarkNode bookmark = new BookmarkNode(BookmarkNode.Bookmark);
|
|
891 bookmark.url = m_url;
|
|
892 bookmark.title = name.text();
|
|
893 m_bookmarksManager.addBookmark(parent, bookmark);
|
|
894 QDialog.accept();
|
|
895 }
|
45
|
896
|
|
897 private:
|
73
|
898
|
|
899 QString m_url;
|
|
900 BookmarksManager m_bookmarksManager;
|
|
901 AddBookmarkProxyModel m_proxyModel;
|
45
|
902 }
|
|
903
|
|
904 import ui_bookmarks;
|
|
905
|
|
906 //class TreeProxyModel;
|
|
907 class BookmarksDialog : public QDialog, public Ui_BookmarksDialog
|
|
908 {
|
74
|
909 mixin Signal!("openUrl", QUrl /*url*/);
|
45
|
910
|
|
911 public:
|
73
|
912
|
|
913 this(QWidget parent = null, BookmarksManager manager = null)
|
74
|
914 //: QDialog(parent)
|
73
|
915 {
|
|
916 m_bookmarksManager = manager;
|
|
917 if (!m_bookmarksManager)
|
|
918 m_bookmarksManager = BrowserApplication.bookmarksManager();
|
|
919 setupUi(this);
|
45
|
920
|
73
|
921 tree.setUniformRowHeights(true);
|
|
922 tree.setSelectionBehavior(QAbstractItemView.SelectRows);
|
|
923 tree.setSelectionMode(QAbstractItemView.ContiguousSelection);
|
|
924 tree.setTextElideMode(Qt.ElideMiddle);
|
|
925 m_bookmarksModel = m_bookmarksManager.bookmarksModel();
|
|
926 m_proxyModel = new TreeProxyModel(this);
|
|
927 search.textChanged.connect(&m_proxyModel.setFilterFixedString);
|
|
928 removeButton.clicked.connect(&tree.removeOne);
|
|
929 m_proxyModel.setSourceModel(m_bookmarksModel);
|
|
930 tree.setModel(m_proxyModel);
|
|
931 tree.setDragDropMode(QAbstractItemView.InternalMove);
|
|
932 tree.setExpanded(m_proxyModel.index(0, 0), true);
|
|
933 tree.setAlternatingRowColors(true);
|
|
934 auto fm = new QFontMetrics(font());
|
|
935 int header = fm.width(QLatin1Char('m')) * 40;
|
|
936 tree.header().resizeSection(0, header);
|
|
937 tree.header().setStretchLastSection(true);
|
|
938 tree.activated.connect(&this.open);
|
|
939 tree.setContextMenuPolicy(Qt.CustomContextMenu);
|
|
940 tree.customContextMenuRequested.connect(&this.customContextMenuRequested);
|
|
941 addFolderButton.clicked.connect(&this.newFolder);
|
|
942 expandNodes(m_bookmarksManager.bookmarks());
|
|
943 setAttribute(Qt.WA_DeleteOnClose);
|
|
944 }
|
|
945
|
|
946 ~this()
|
|
947 {
|
|
948 if (saveExpandedNodes(tree.rootIndex()))
|
|
949 m_bookmarksManager.changeExpanded();
|
|
950 }
|
45
|
951
|
|
952 private:
|
73
|
953
|
|
954 void customContextMenuRequested(QPoint pos)
|
|
955 {
|
|
956 QMenu menu;
|
|
957 QModelIndex index = tree.indexAt(pos);
|
|
958 index = index.sibling(index.row(), 0);
|
|
959 if (index.isValid() && !tree.model().hasChildren(index)) {
|
|
960 menu.addAction(tr("Open"), this, SLOT(open()));
|
|
961 menu.addSeparator();
|
|
962 }
|
|
963 menu.addAction(tr("Delete"), tree, SLOT(removeOne()));
|
|
964 menu.exec(QCursor.pos());
|
|
965 }
|
|
966
|
|
967 void open()
|
|
968 {
|
|
969 QModelIndex index = tree.currentIndex();
|
|
970 if (!index.parent().isValid())
|
|
971 return;
|
74
|
972 openUrl.emit(index.sibling(index.row(), 1).data(BookmarksModel.UrlRole).toUrl());
|
73
|
973 }
|
|
974
|
|
975 void newFolder()
|
|
976 {
|
|
977 QModelIndex currentIndex = tree.currentIndex();
|
|
978 QModelIndex idx = currentIndex;
|
|
979 if (idx.isValid() && !idx.model().hasChildren(idx))
|
|
980 idx = idx.parent();
|
|
981 if (!idx.isValid())
|
|
982 idx = tree.rootIndex();
|
|
983 idx = m_proxyModel.mapToSource(idx);
|
|
984 BookmarkNode parent = m_bookmarksManager.bookmarksModel().node(idx);
|
|
985 BookmarkNode node = new BookmarkNode(BookmarkNode.Folder);
|
|
986 node.title = tr("New Folder");
|
|
987 m_bookmarksManager.addBookmark(parent, node, currentIndex.row() + 1);
|
|
988 }
|
45
|
989
|
73
|
990 private:
|
|
991 void expandNodes(BookmarkNode node)
|
|
992 {
|
|
993 for (int i = 0; i < node.children().count(); ++i) {
|
|
994 BookmarkNode childNode = node.children()[i];
|
|
995 if (childNode.expanded) {
|
|
996 QModelIndex idx = m_bookmarksModel.index(childNode);
|
|
997 idx = m_proxyModel.mapFromSource(idx);
|
|
998 tree.setExpanded(idx, true);
|
|
999 expandNodes(childNode);
|
|
1000 }
|
|
1001 }
|
|
1002 }
|
45
|
1003
|
73
|
1004 bool saveExpandedNodes(QModelIndex parent)
|
|
1005 {
|
|
1006 bool changed = false;
|
|
1007 for (int i = 0; i < m_proxyModel.rowCount(parent); ++i) {
|
|
1008 QModelIndex child = m_proxyModel.index(i, 0, parent);
|
|
1009 QModelIndex sourceIndex = m_proxyModel.mapToSource(child);
|
|
1010 BookmarkNode childNode = m_bookmarksModel.node(sourceIndex);
|
|
1011 bool wasExpanded = childNode.expanded;
|
|
1012 if (tree.isExpanded(child)) {
|
|
1013 childNode.expanded = true;
|
|
1014 changed |= saveExpandedNodes(child);
|
|
1015 } else {
|
|
1016 childNode.expanded = false;
|
|
1017 }
|
|
1018 changed |= (wasExpanded != childNode.expanded);
|
|
1019 }
|
|
1020 return changed;
|
|
1021 }
|
|
1022
|
|
1023 BookmarksManager m_bookmarksManager;
|
|
1024 BookmarksModel m_bookmarksModel;
|
|
1025 TreeProxyModel m_proxyModel;
|
72
|
1026 }
|
45
|
1027
|
74
|
1028
|
72
|
1029 import qt.gui.QToolBar;
|
|
1030
|
74
|
1031
|
45
|
1032 class BookmarksToolBar : public QToolBar
|
|
1033 {
|
74
|
1034 mixin Signal!("openUrl", QUrl /*url*/);
|
45
|
1035
|
|
1036 public:
|
|
1037
|
73
|
1038 this(BookmarksModel model, QWidget parent = null)
|
|
1039 {
|
|
1040 super(tr("Bookmark"), parent);
|
|
1041 m_bookmarksModel = model;
|
|
1042 this.actionTriggered.connect(&this.triggered);
|
|
1043 setRootIndex(model.index(0, 0));
|
|
1044 m_bookmarksModel.modelReset.connect(&this.build);
|
|
1045 m_bookmarksModel.rowsInserted.connect(&this.build);
|
|
1046 m_bookmarksModel.rowsRemoved.connect(&this.build);
|
|
1047 m_bookmarksModel.dataChanged.connect(&this.build);
|
|
1048 setAcceptDrops(true);
|
|
1049 }
|
45
|
1050
|
74
|
1051 void setRootIndex(QModelIndex index)
|
73
|
1052 {
|
|
1053 m_root = index;
|
|
1054 build();
|
|
1055 }
|
|
1056
|
|
1057 QModelIndex rootIndex()
|
|
1058 {
|
|
1059 return m_root;
|
|
1060 }
|
45
|
1061
|
|
1062 protected:
|
|
1063
|
73
|
1064 void dragEnterEvent(QDragEnterEvent event)
|
|
1065 {
|
|
1066 const QMimeData mimeData = event.mimeData();
|
|
1067 if (mimeData.hasUrls())
|
|
1068 event.acceptProposedAction();
|
|
1069 QToolBar.dragEnterEvent(event);
|
|
1070 }
|
45
|
1071
|
73
|
1072 void dropEvent(QDropEvent event)
|
|
1073 {
|
|
1074 const QMimeData mimeData = event.mimeData();
|
|
1075 if (mimeData.hasUrls() && mimeData.hasText()) {
|
74
|
1076 QUrl[] urls = mimeData.urls();
|
73
|
1077 QAction action = actionAt(event.pos());
|
|
1078 QString dropText;
|
|
1079 if (action)
|
|
1080 dropText = action.text();
|
|
1081 int row = -1;
|
|
1082 QModelIndex parentIndex = m_root;
|
|
1083 for (int i = 0; i < m_bookmarksModel.rowCount(m_root); ++i) {
|
|
1084 QModelIndex idx = m_bookmarksModel.index(i, 0, m_root);
|
|
1085 QString title = idx.data().toString();
|
|
1086 if (title == dropText) {
|
|
1087 row = i;
|
|
1088 if (m_bookmarksModel.hasChildren(idx)) {
|
|
1089 parentIndex = idx;
|
|
1090 row = -1;
|
|
1091 }
|
|
1092 break;
|
|
1093 }
|
|
1094 }
|
|
1095 BookmarkNode bookmark = new BookmarkNode(BookmarkNode.Bookmark);
|
|
1096 bookmark.url = urls.at(0).toString();
|
|
1097 bookmark.title = mimeData.text();
|
45
|
1098
|
73
|
1099 BookmarkNode parent = m_bookmarksModel.node(parentIndex);
|
|
1100 BookmarksManager bookmarksManager = m_bookmarksModel.bookmarksManager();
|
|
1101 bookmarksManager.addBookmark(parent, bookmark, row);
|
|
1102 event.acceptProposedAction();
|
|
1103 }
|
|
1104 QToolBar.dropEvent(event);
|
|
1105 }
|
45
|
1106
|
|
1107 private:
|
73
|
1108
|
|
1109 void triggered(QAction action)
|
|
1110 {
|
|
1111 QVariant v = action.data();
|
74
|
1112 if (v.canConvert!(QUrl)()) {
|
|
1113 openUrl.emit(v.toUrl());
|
73
|
1114 }
|
|
1115 }
|
|
1116
|
|
1117 void activated(QModelIndex index)
|
|
1118 {
|
74
|
1119 openUrl.emit(index.data(BookmarksModel.UrlRole).toUrl());
|
73
|
1120 }
|
|
1121
|
|
1122 void build()
|
|
1123 {
|
|
1124 clear();
|
|
1125 for (int i = 0; i < m_bookmarksModel.rowCount(m_root); ++i) {
|
|
1126 QModelIndex idx = m_bookmarksModel.index(i, 0, m_root);
|
|
1127 if (m_bookmarksModel.hasChildren(idx)) {
|
|
1128 QToolButton button = new QToolButton(this);
|
|
1129 button.setPopupMode(QToolButton.InstantPopup);
|
|
1130 button.setArrowType(Qt.DownArrow);
|
|
1131 button.setText(idx.data().toString());
|
|
1132 ModelMenu menu = new ModelMenu(this);
|
|
1133 menu.activated.connect(&this.activated);
|
|
1134 menu.setModel(m_bookmarksModel);
|
|
1135 menu.setRootIndex(idx);
|
|
1136 menu.addAction(new QAction(menu));
|
|
1137 button.setMenu(menu);
|
|
1138 button.setToolButtonStyle(Qt.ToolButtonTextOnly);
|
|
1139 QAction a = addWidget(button);
|
|
1140 a.setText(idx.data().toString());
|
|
1141 } else {
|
|
1142 QAction action = addAction(idx.data().toString());
|
|
1143 action.setData(idx.data(BookmarksModel.UrlRole));
|
|
1144 }
|
|
1145 }
|
|
1146 }
|
|
1147
|
|
1148 private:
|
|
1149
|
|
1150 BookmarksModel m_bookmarksModel;
|
|
1151 QPersistentModelIndex m_root;
|
45
|
1152 }
|