2
This file is part of the Bookmarks plasmoid, part of the KDE project.
4
Copyright 2009-2010 Friedrich W. H. Kossebau <kossebau@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as
8
published by the Free Software Foundation; either version 2 of
9
the License or (at your option) version 3 or any later version
10
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12
defined in Section 14 of version 3 of the license.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "bookmarksplasmoid.h"
26
#include "generalconfigeditor.h"
27
#include "bookmarkowner.h"
29
#include <Plasma/IconWidget>
30
#include <Plasma/ToolTipManager>
32
#include <KConfigDialog>
33
#include <KStandardAction>
34
#include <KIconLoader>
36
#include <KBookmarkMenu>
37
#include <KBookmarkGroup>
39
#include <QtGui/QPainter>
40
#include <QtGui/QGraphicsLinearLayout>
46
static const char bookmarkFolderAddressConfigKey[] = "BookmarkFolderAddress";
49
BookmarksPlasmoid::BookmarksPlasmoid(QObject* parent, const QVariantList& args)
50
: Applet(parent, args),
59
void BookmarksPlasmoid::init()
61
mBookmarkManager = KBookmarkManager::userBookmarksManager();
62
mBookmarkManager->setEditorOptions(name(), true);
63
connect(mBookmarkManager, SIGNAL(changed(const QString&, const QString&)), SLOT(onBookmarksChanged(const QString&)));
66
setHasConfigurationInterface(true);
67
connect(this, SIGNAL(activate()), SLOT(toggleMenu()));
68
Plasma::ToolTipManager::self()->registerWidget(this);
71
KAction* editorOpener = KStandardAction::editBookmarks(this, SLOT(editBookmarks()), this);
72
mContextualActions.append(editorOpener);
75
setAspectRatioMode(ConstrainedSquare);
76
setBackgroundHints(NoBackground);
78
QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(this);
79
layout->setContentsMargins(0, 0, 0, 0);
80
layout->setSpacing(0);
82
mIcon = new IconWidget(KIcon("bookmarks"),"",this);
83
mIcon->setFlag(ItemIsMovable, false);
84
connect(mIcon, SIGNAL(pressed(bool)), SLOT(toggleMenu(bool)));
85
layout->addItem(mIcon);
91
QList<QAction*> BookmarksPlasmoid::contextualActions()
93
return mContextualActions;
96
void BookmarksPlasmoid::updateFolderData()
98
const KBookmark bookmark = mBookmarkManager->findByAddress(mBookmarkFolderAddress);
100
KBookmarkGroup bookmarkFolder =
101
(bookmark.isNull() || ! bookmark.isGroup()) ? mBookmarkManager->root() : bookmark.toGroup();
103
const bool isRoot = (! bookmarkFolder.hasParent());
105
const QString iconName = isRoot ? QString::fromLatin1("bookmarks") : bookmarkFolder.icon();
106
const QString folderName = isRoot ? i18nc("name of the container of all browser bookmarks",
108
bookmarkFolder.text();
109
const QString comment = isRoot ? i18n("Quick access to your bookmarks.") : bookmarkFolder.description();
112
mIcon->setIcon(iconName);
114
Plasma::ToolTipContent toolTipContent(folderName, comment, KIcon(iconName));
115
Plasma::ToolTipManager::self()->setContent(this, toolTipContent);
118
void BookmarksPlasmoid::toggleMenu(bool toggle)
123
Plasma::ToolTipManager::self()->hide(this);
126
const bool isFirstTime = (mBookmarkOwner == 0);
128
mBookmarkOwner = new BookmarkOwner();
130
delete mBookmarkMenu;
132
KMenu* menu = new KMenu();
133
menu->setAttribute(Qt::WA_DeleteOnClose);
134
connect(menu, SIGNAL(aboutToHide()), mIcon, SLOT(setUnpressed()));
135
// TODO: only renew if manager emits changed
136
mBookmarkMenu = new KBookmarkMenu(mBookmarkManager, mBookmarkOwner, menu, mBookmarkFolderAddress);
138
menu->popup(popupPosition(menu->size()));
139
menu->move(popupPosition(menu->size()));
143
void BookmarksPlasmoid::toggleMenu()
148
void BookmarksPlasmoid::createConfigurationInterface(KConfigDialog* parent)
150
mGeneralConfigEditor = new GeneralConfigEditor(mBookmarkManager, parent);
151
mGeneralConfigEditor->setBookmarkFolderAddress(mBookmarkFolderAddress);
152
const QString pageName = i18nc("@title:tab name of settings page with general parameters","General");
153
parent->addPage(mGeneralConfigEditor, pageName, icon());
154
connect(parent, SIGNAL(applyClicked()), SLOT(applyConfigChanges()));
155
connect(parent, SIGNAL(okClicked()), SLOT(applyConfigChanges()));
158
void BookmarksPlasmoid::applyConfigChanges()
160
const QString& bookmarkFolderAddress = mGeneralConfigEditor->bookmarkFolderAddress();
162
if (mBookmarkFolderAddress != bookmarkFolderAddress) {
163
KConfigGroup configGroup = config();
164
configGroup.writeEntry(bookmarkFolderAddressConfigKey, mBookmarkFolderAddress);
166
emit configNeedsSaving();
170
void BookmarksPlasmoid::configChanged()
173
KConfigGroup configGroup = config();
174
const QString bookmarkFolderAddress = configGroup.readEntry(bookmarkFolderAddressConfigKey, mBookmarkFolderAddress);
176
if (mBookmarkFolderAddress != bookmarkFolderAddress) {
177
mBookmarkFolderAddress = bookmarkFolderAddress;
182
void BookmarksPlasmoid::editBookmarks()
184
mBookmarkManager->slotEditBookmarksAtAddress(mBookmarkFolderAddress);
187
void BookmarksPlasmoid::onBookmarksChanged(const QString& address)
194
BookmarksPlasmoid::~BookmarksPlasmoid()
196
delete mBookmarkMenu;
197
delete mBookmarkOwner;