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