1 | // -*- c-basic-offset:4; indent-tabs-mode:nil -*- |
2 | // vim: set ts=4 sts=4 sw=4 et: |
3 | /* This file is part of the KDE libraries |
4 | Copyright 2007 Daniel Teske <teske@squorn.de> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License version 2 as published by the Free Software Foundation. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | #ifndef __kbookmarkdialog_h |
21 | #define __kbookmarkdialog_h |
22 | |
23 | #include "kbookmark.h" |
24 | #include <kdialog.h> |
25 | #include <kurl.h> |
26 | |
27 | class KBookmarkManager; |
28 | class QWidget; |
29 | class QLabel; |
30 | class QTreeWidget; |
31 | class KLineEdit; |
32 | class QTreeWidgetItem; |
33 | class QGridLayout; |
34 | |
35 | /** |
36 | * This class provides a Dialog for editing properties, adding Bookmarks and creating new folders. |
37 | * It can be used to show dialogs for common tasks with bookmarks. |
38 | * |
39 | * It is used by KBookmarkMenu to show a dialog for "Properties", "Add Bookmark" and "Create New Folder". |
40 | * If you want to customize those dialogs, derive from KBookmarkOwner and reimplement bookmarkDialog(), |
41 | * return a KBookmarkDialog subclass and reimplement initLayout(), aboutToShow() and save(). |
42 | **/ |
43 | |
44 | class KIO_EXPORT KBookmarkDialog : public KDialog |
45 | { |
46 | Q_OBJECT |
47 | |
48 | public: |
49 | /** |
50 | * Creates a new KBookmarkDialog |
51 | */ |
52 | KBookmarkDialog( KBookmarkManager *, QWidget * = 0); |
53 | /** |
54 | * shows a propeties dialog |
55 | * Note: That this updates the bookmark and calls KBookmarkManager::emitChanged |
56 | */ |
57 | KBookmark editBookmark(const KBookmark & bm); |
58 | /** |
59 | * shows a add Bookmark dialog |
60 | * Note: That this updates the bookmark and calls KBookmarkManager::emitChanged |
61 | */ |
62 | KBookmark addBookmark(const QString & title, const KUrl & url, KBookmark parent = KBookmark()); |
63 | /** |
64 | * Creates a folder from a list of bookmarks |
65 | * Note: That this updates the bookmark and calls KBookmarkManager::emitChanged |
66 | */ |
67 | KBookmarkGroup addBookmarks(const QList< QPair<QString, QString> > & list, const QString & name = QString(), KBookmarkGroup parent = KBookmarkGroup()); |
68 | /** |
69 | * A dialog to create a new folder. |
70 | */ |
71 | KBookmarkGroup createNewFolder(const QString & name, KBookmark parent = KBookmark()); |
72 | /** |
73 | * A dialog to select a folder. |
74 | */ |
75 | KBookmarkGroup selectFolder(KBookmark start = KBookmark()); |
76 | |
77 | protected: |
78 | typedef enum { NewFolder, NewBookmark, EditBookmark, NewMultipleBookmarks, SelectFolder } BookmarkDialogMode; |
79 | /** |
80 | * initLayout is called to set the dialog up, indepent from the mode |
81 | * If you want to add widgets or a custom layout, reimplement this function. |
82 | * The default implementation is rather simple, take a look at the source. |
83 | * |
84 | */ |
85 | virtual void initLayout(); |
86 | /** |
87 | * aboutToShow is called immediately before exec() |
88 | * Reimplement this to show or hide UI elements for certain modes. |
89 | * |
90 | */ |
91 | virtual void aboutToShow(BookmarkDialogMode mode); |
92 | /** |
93 | * save all your custom data in this method |
94 | * This is called after the users has accepted() the dialog. |
95 | * |
96 | */ |
97 | virtual void save(BookmarkDialogMode mode, const KBookmark &); |
98 | |
99 | /** |
100 | * selects the specified bookmark in the folder tree |
101 | */ |
102 | void setParentBookmark(const KBookmark & bm); |
103 | /** |
104 | * returns the selected bookmark in the folder tree, or the root (top-level) |
105 | * bookmark if none was selected |
106 | */ |
107 | KBookmarkGroup parentBookmark(); |
108 | |
109 | |
110 | void slotButtonClicked(int); |
111 | |
112 | // TODO KDE5: move all these variables to a d pointer; make as many methods private as possible. |
113 | BookmarkDialogMode m_mode; |
114 | void fillGroup( QTreeWidgetItem * parentItem, const KBookmarkGroup &group); |
115 | QWidget * m_main; |
116 | KLineEdit * m_url; |
117 | KLineEdit * m_title; |
118 | KLineEdit * ; |
119 | QLabel * m_titleLabel; |
120 | QLabel * m_urlLabel; |
121 | QLabel * ; |
122 | QTreeWidget * m_folderTree; |
123 | KBookmarkManager * m_mgr; |
124 | KBookmark m_bm; |
125 | QList<QPair<QString, QString> > m_list; |
126 | bool m_layout; |
127 | // WARNING: do not add new member variables here; replace one of the pointers with a d pointer, |
128 | // assuming that variable isn't used anywhere in apps... |
129 | |
130 | void initLayoutPrivate(); |
131 | |
132 | protected Q_SLOTS: |
133 | void newFolderButton(); |
134 | |
135 | private: |
136 | void fillGroup(QTreeWidgetItem* parentItem, const KBookmarkGroup& group, const KBookmarkGroup& selectGroup); |
137 | }; |
138 | |
139 | #endif |
140 | |
141 | |