2 Copyright 2007 Robert Knight <robertknight@gmail.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "applet/applet.h"
24 #include <QtGui/QAction>
25 #include <QtGui/QApplication>
26 #include <QtGui/QGraphicsView>
27 #include <QtGui/QCheckBox>
28 #include <QtGui/QVBoxLayout>
29 #include <QtGui/QLabel>
30 #include <QtGui/QGraphicsLinearLayout>
35 #include <KConfigDialog>
39 #include <Plasma/IconWidget>
40 #include <Plasma/Containment>
41 #include <Plasma/View>
42 #include <Plasma/ToolTipManager>
45 #include "ui/launcher.h"
46 #include "core/recentapplications.h"
48 class LauncherApplet::Private
51 Private(LauncherApplet
*lApplet
) : launcher(0), switcher(0), q(lApplet
) { }
55 void createLauncher();
58 Kickoff::Launcher
*launcher
;
60 QCheckBox
*switchOnHoverCheckBox
;
61 QList
<QAction
*> actions
;
66 void LauncherApplet::Private::createLauncher()
72 launcher
= new Kickoff::Launcher(q
);
73 launcher
->setAttribute(Qt::WA_NoSystemBackground
);
74 launcher
->setAutoHide(true);
75 QObject::connect(launcher
, SIGNAL(aboutToHide()), q
, SLOT(hidePopup()));
76 //launcher->resize(launcher->sizeHint());
77 //QObject::connect(launcher, SIGNAL(aboutToHide()), icon, SLOT(setUnpressed()));
78 //QObject::connect(launcher, SIGNAL(configNeedsSaving()), q, SIGNAL(configNeedsSaving()));
81 void LauncherApplet::Private::initToolTip()
83 Plasma::ToolTipContent
data(i18n("Kickoff Application Launcher"),
84 i18n("Favorites, applications, computer places, "
85 "recently used items and desktop sessions"),
86 q
->popupIcon().pixmap(IconSize(KIconLoader::Desktop
)));
87 Plasma::ToolTipManager::self()->setContent(q
, data
);
90 LauncherApplet::LauncherApplet(QObject
*parent
, const QVariantList
&args
)
91 : Plasma::PopupApplet(parent
, args
),
94 KGlobal::locale()->insertCatalog("plasma_applet_launcher");
95 setHasConfigurationInterface(true);
96 setPopupIcon("start-here-kde");
99 LauncherApplet::~LauncherApplet()
104 void LauncherApplet::init()
106 if (KService::serviceByStorageId("kde4-kmenuedit.desktop")) {
107 QAction
* menueditor
= new QAction(i18n("Menu Editor"), this);
108 d
->actions
.append(menueditor
);
109 connect(menueditor
, SIGNAL(triggered(bool)), this, SLOT(startMenuEditor()));
112 Q_ASSERT(! d
->switcher
);
113 d
->switcher
= new QAction(i18n("Switch to Classic Menu Style"), this);
114 d
->actions
.append(d
->switcher
);
115 connect(d
->switcher
, SIGNAL(triggered(bool)), this, SLOT(switchMenuStyle()));
117 constraintsEvent(Plasma::ImmutableConstraint
);
118 Plasma::ToolTipManager::self()->registerWidget(this);
121 void LauncherApplet::constraintsEvent(Plasma::Constraints constraints
)
123 if ((constraints
& Plasma::ImmutableConstraint
) && d
->switcher
) {
124 d
->switcher
->setVisible(immutability() == Plasma::Mutable
);
128 void LauncherApplet::switchMenuStyle()
131 containment()->addApplet("simplelauncher", QVariantList(), geometry());
136 void LauncherApplet::startMenuEditor()
138 KProcess::execute("kmenuedit");
141 void LauncherApplet::createConfigurationInterface(KConfigDialog
*parent
)
143 QWidget
*widget
= new QWidget(parent
);
144 QVBoxLayout
*widgetLayout
= new QVBoxLayout(widget
);
145 widget
->setLayout(widgetLayout
);
147 d
->switchOnHoverCheckBox
= new QCheckBox(i18n("Switch tabs on hover"), widget
);
148 widgetLayout
->addWidget(d
->switchOnHoverCheckBox
);
150 widgetLayout
->addStretch();
152 connect(parent
, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
153 connect(parent
, SIGNAL(okClicked()), this, SLOT(configAccepted()));
154 parent
->addPage(widget
, i18n("General"), icon());
157 d
->switchOnHoverCheckBox
->setChecked(d
->launcher
->switchTabsOnHover());
160 void LauncherApplet::popupEvent(bool show
)
163 Plasma::ToolTipManager::self()->clearContent(this);
164 d
->launcher
->setLauncherOrigin(popupPlacement(), location());
169 void LauncherApplet::toolTipAboutToShow()
171 if (d
->launcher
->isVisible()) {
172 Plasma::ToolTipManager::self()->clearContent(this);
178 void LauncherApplet::configAccepted()
180 bool switchTabsOnHover
= d
->switchOnHoverCheckBox
->isChecked();
182 // TODO: should this be moved into Launcher as well? perhaps even the config itself?
183 KConfigGroup cg
= globalConfig();
184 cg
.writeEntry("SwitchTabsOnHover", switchTabsOnHover
);
185 emit
configNeedsSaving();
188 d
->launcher
->setSwitchTabsOnHover(switchTabsOnHover
);
191 QList
<QAction
*> LauncherApplet::contextualActions()
196 QWidget
*LauncherApplet::widget()
202 #include "applet.moc"