Skip to content
Browse files

Razor-panel: New plugin API

  • Loading branch information...
1 parent bbe7898 commit 46657fc527ba3f5abe717005f6b7b755d0118e8e @SokoloffA SokoloffA committed Oct 26, 2012
View
83 libraries/razorqt/powermanager.cpp
@@ -40,21 +40,30 @@ class MessageBox: public QMessageBox
public:
explicit MessageBox(QWidget *parent = 0): QMessageBox(parent) {}
- static QMessageBox::StandardButton question(QWidget* parent,
- const QString& title,
- const QString& text,
- StandardButton button0,
- StandardButton button1)
+ static QWidget *parentWidget()
{
- MessageBox msgBox(parent);
+ QWidgetList widgets = QApplication::topLevelWidgets();
+
+ if (widgets.count())
+ return widgets.at(0);
+ else
+ return 0;
+ }
+
+ static bool question(const QString& title, const QString& text)
+ {
+ MessageBox msgBox(parentWidget());
msgBox.setWindowTitle(title);
msgBox.setText(text);
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- if (msgBox.exec() == QMessageBox::Yes)
- return QMessageBox::Yes;
- else
- return QMessageBox::No;
+ return (msgBox.exec() == QMessageBox::Yes);
+ }
+
+
+ static void warning(const QString& title, const QString& text)
+ {
+ QMessageBox::warning(parentWidget(), tr("Razor Power Manager Error"), tr("Hibernate failed."));
}
@@ -69,8 +78,7 @@ class MessageBox: public QMessageBox
};
PowerManager::PowerManager(QObject * parent)
- : QObject(parent),
- m_parentWidget(0)
+ : QObject(parent)
{
libTranslate("librazorqt");
m_power = new RazorPower(this);
@@ -130,74 +138,57 @@ QList<QAction*> PowerManager::availableActions()
}
-
-
void PowerManager::suspend()
{
- if (MessageBox::question(m_parentWidget, tr("Razor Session Suspend"),
- tr("Do you want to really suspend your computer?<p>Suspends the computer into a low power state. System state is not preserved if the power is lost."),
- QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+ if (MessageBox::question(tr("Razor Session Suspend"),
+ tr("Do you want to really suspend your computer?<p>Suspends the computer into a low power state. System state is not preserved if the power is lost.")))
{
- return;
+ m_power->suspend();
}
-
- m_power->suspend();
}
void PowerManager::hibernate()
{
- if (MessageBox::question(m_parentWidget, tr("Razor Session Hibernate"),
- tr("Do you want to really hibernate your computer?<p>Hibernates the computer into a low power state. System state is preserved if the power is lost."),
- QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+ if (MessageBox::question(tr("Razor Session Hibernate"),
+ tr("Do you want to really hibernate your computer?<p>Hibernates the computer into a low power state. System state is preserved if the power is lost.")))
{
- return;
+ m_power->hibernate();
}
-
- m_power->hibernate();
}
void PowerManager::reboot()
{
- if (MessageBox::question(m_parentWidget, tr("Razor Session Reboot"),
- tr("Do you want to really restart your computer? All unsaved work will be lost..."),
- QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+ if (MessageBox::question(tr("Razor Session Reboot"),
+ tr("Do you want to really restart your computer? All unsaved work will be lost...")))
{
- return;
+ m_power->reboot();
}
-
- m_power->reboot();
}
void PowerManager::shutdown()
{
- if (MessageBox::question(m_parentWidget, tr("Razor Session Shutdown"),
- tr("Do you want to really switch off your computer? All unsaved work will be lost..."),
- QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+ if (MessageBox::question(tr("Razor Session Shutdown"),
+ tr("Do you want to really switch off your computer? All unsaved work will be lost...")))
{
- return;
+ m_power->shutdown();
}
-
- m_power->shutdown();
}
void PowerManager::logout()
{
- if (MessageBox::question(m_parentWidget, tr("Razor Session Logout"),
- tr("Do you want to really logout? All unsaved work will be lost..."),
- QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
+ if (MessageBox::question(tr("Razor Session Logout"),
+ tr("Do you want to really logout? All unsaved work will be lost...")))
{
- return;
+ m_power->logout();
}
-
- m_power->logout();
}
void PowerManager::hibernateFailed()
{
- QMessageBox::warning(m_parentWidget, tr("Razor Power Manager Error"), tr("Hibernate failed."));
+ MessageBox::warning(tr("Razor Power Manager Error"), tr("Hibernate failed."));
}
void PowerManager::suspendFailed()
{
- QMessageBox::warning(m_parentWidget, tr("Razor Power Manager Error"), tr("Suspend failed."));
+ MessageBox::warning(tr("Razor Power Manager Error"), tr("Suspend failed."));
}
View
4 libraries/razorqt/powermanager.h
@@ -43,8 +43,7 @@ class PowerManager : public QObject
PowerManager(QObject * parent);
~PowerManager();
QList<QAction*> availableActions();
- QWidget* parentWidget() const { return m_parentWidget; }
- void setParentWidget(QWidget* parentWidget) { m_parentWidget = parentWidget; }
+
public slots:
// power management
void suspend();
@@ -56,7 +55,6 @@ public slots:
private:
RazorPower * m_power;
- QWidget * m_parentWidget;
private slots:
void hibernateFailed();
View
19 libraries/razorqt/razorsettings.cpp
@@ -108,6 +108,25 @@ RazorSettings::RazorSettings(const QString& module, QObject* parent) :
/************************************************
************************************************/
+RazorSettings::RazorSettings(const QString &fileName, QSettings::Format format, QObject *parent):
+ QSettings(fileName, format, parent),
+ d_ptr(new RazorSettingsPrivate(this))
+{
+ // HACK: we need to ensure that the user (~/.config/razor/<module>.conf)
+ // exists to have functional mWatcher
+ if (!contains("__userfile__"))
+ {
+ setValue("__userfile__", true);
+ sync();
+ }
+ d_ptr->mWatcher.addPath(this->fileName());
+ connect(&(d_ptr->mWatcher), SIGNAL(fileChanged(QString)), this, SLOT(fileChanged()));
+}
+
+
+/************************************************
+
+ ************************************************/
RazorSettings::RazorSettings(const QSettings* parentSettings, const QString& subGroup, QObject* parent):
QSettings(parentSettings->organizationName(), parentSettings->applicationName(), parent),
d_ptr(new RazorSettingsPrivate(this))
View
1 libraries/razorqt/razorsettings.h
@@ -58,6 +58,7 @@ class RazorSettings : public QSettings
//explicit RazorSettings(QObject* parent=0);
explicit RazorSettings(const QSettings* parentSettings, const QString& subGroup, QObject* parent=0);
explicit RazorSettings(const QSettings& parentSettings, const QString& subGroup, QObject* parent=0);
+ RazorSettings(const QString &fileName, QSettings::Format format, QObject *parent = 0);
~RazorSettings();
static const GlobalRazorSettings *globalSettings();
View
1 libraries/razorqxt/qxtglobalshortcut.cpp
@@ -48,7 +48,6 @@ QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate()
bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)
{
Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier;
- qDebug() << shortcut.isEmpty();
key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]);
mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods);
const quint32 nativeKey = nativeKeycode(key);
View
1 libraries/razorqxt/qxtglobalshortcut_mac.cpp
@@ -193,7 +193,6 @@ bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativ
keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id);
keyRefs.insert(keyID.id, ref);
}
- qDebug() << ref;
return rv;
}
View
38 razorqt-panel/CMakeLists.txt
@@ -19,22 +19,23 @@ endmacro()
# cmake -DCLOCK_PLUGIN=Yes .. # Enable clock plugin
# cmake -DCLOCK_PLUGIN=No .. # Disable clock plugin
-setByDefault(CLOCK_PLUGIN Yes )
-setByDefault(DESKTOPSWITCH_PLUGIN Yes )
-setByDefault(QUICKLAUNCH_PLUGIN Yes )
-setByDefault(TRAY_PLUGIN Yes )
-setByDefault(MAINMENU_PLUGIN Yes )
-setByDefault(TASKBAR_PLUGIN Yes )
-setByDefault(SCREENSAVER_PLUGIN Yes )
-setByDefault(SHOWDESKTOP_PLUGIN Yes)
-setByDefault(COLORPICKER_PLUGIN Yes)
-setByDefault(MOUNT_PLUGIN Yes)
-setByDefault(HELLOWORLD_PLUGIN No)
-setByDefault(CPULOAD_PLUGIN Yes)
-setByDefault(NETWORKMONITOR_PLUGIN Yes)
-setByDefault(SENSORS_PLUGIN Yes)
-setByDefault(VOLUME_PLUGIN Yes)
-setByDefault(KBINDICATOR_PLUGIN Yes)
+setByDefault(CLOCK_PLUGIN No)
+setByDefault(DESKTOPSWITCH_PLUGIN No)
+setByDefault(QUICKLAUNCH_PLUGIN No)
+setByDefault(TRAY_PLUGIN No)
+setByDefault(MAINMENU_PLUGIN Yes)
+setByDefault(TASKBAR_PLUGIN No)
+setByDefault(SCREENSAVER_PLUGIN No)
+setByDefault(SHOWDESKTOP_PLUGIN No)
+setByDefault(COLORPICKER_PLUGIN No)
+setByDefault(MOUNT_PLUGIN No)
+setByDefault(HELLOWORLD_PLUGIN Yes)
+setByDefault(CPULOAD_PLUGIN No)
+setByDefault(NETWORKMONITOR_PLUGIN No)
+setByDefault(SENSORS_PLUGIN No)
+setByDefault(VOLUME_PLUGIN No)
+setByDefault(KBINDICATOR_PLUGIN No)
+setByDefault(TEATIME_PLUGIN Yes)
# *******************************************************************
@@ -189,6 +190,11 @@ if (KBINDICATOR_PLUGIN)
add_subdirectory(plugin-kbindicator)
endif (KBINDICATOR_PLUGIN)
+if (TEATIME_PLUGIN)
+ set(ENABLED_PLUGINS ${ENABLED_PLUGINS} "TeaTime")
+ add_subdirectory(plugin-teatime)
+endif (TEATIME_PLUGIN)
+
message(STATUS "**************** The following plugins will be built ****************")
foreach (PLUGIN_STR ${ENABLED_PLUGINS})
View
23 razorqt-panel/panel/CMakeLists.txt
@@ -5,36 +5,41 @@ set(PROJECT razor-panel )
set(QT_USE_QTXML 1)
set(QT_USE_QTDBUS 1)
-set(razor-panel_H_FILES
+
+set(razor-panel_PRIV_H_FILES
razorpanel.h
razorpanel_p.h
- razorpanelplugin.h
- razorpanelplugin_p.h
razorpanelapplication.h
razorpanellayout.h
razorpanelpluginconfigdialog.h
configpaneldialog.h
+ plugin.h
+)
+
+set(razor-panel_PUB_H_FILES
+ irazorpanelplugin.h
+ irazorpanel.h
)
set(razor-panel_CPP_FILES
main.cpp
razorpanel.cpp
- razorpanelplugin.cpp
razorpanelapplication.cpp
razorpanellayout.cpp
razorpanelpluginconfigdialog.cpp
configpaneldialog.cpp
+ plugin.cpp
)
set(MOCS
razorpanel.h
razorpanel_p.h
- razorpanelplugin.h
- razorpanelplugin_p.h
razorpanelapplication.h
razorpanellayout.h
razorpanelpluginconfigdialog.h
configpaneldialog.h
+ irazorpanelplugin.h
+ plugin.h
)
set(LIBRARIES
@@ -97,7 +102,8 @@ qt4_add_resources(QRC_SOURCES ${RESOURCES})
include(RazorTranslate)
razor_translate_ts(razor-runner_QM_FILES
SOURCES
- ${razor-panel_H_FILES}
+ ${razor-panel_PUB_H_FILES}
+ ${razor-panel_PRIV_H_FILES}
${razor-panel_CPP_FILES}
${razor-panel_UI_FILES}
)
@@ -108,8 +114,9 @@ set (PLUGIN_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/razor-panel/)
add_definitions(-DPLUGIN_DIR=\"${PLUGIN_DIR}\")
message(STATUS "Panel plugins location: ${PLUGIN_DIR}")
-add_executable(${PROJECT} ${razor-panel_H_FILES} ${razor-panel_CPP_FILES} ${MOC_SOURCES} ${razor-runner_QM_FILES} ${QRC_SOURCES} ${UI_HEADERS})
+add_executable(${PROJECT} ${razor-panel_PUB_H_FILES} ${razor-panel_PRIV_H_FILES} ${razor-panel_CPP_FILES} ${MOC_SOURCES} ${razor-runner_QM_FILES} ${QRC_SOURCES} ${UI_HEADERS})
target_link_libraries(${PROJECT} ${LIBRARIES} ${QT_LIBRARIES})
install(TARGETS ${PROJECT} RUNTIME DESTINATION bin)
install(FILES ${CONFIG_FILES} DESTINATION ${RAZOR_ETC_XDG_DIRECTORY}/razor/razor-panel/)
+install(FILES ${razor-panel_PUB_H_FILES} DESTINATION include/razorqt)
View
50 razorqt-panel/panel/irazorpanel.h
@@ -0,0 +1,50 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Alexander Sokoloff <sokoloff.a@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+
+#ifndef IRAZORPANEL_H
+#define IRAZORPANEL_H
+#include <QRect>
+
+class IRazorPanel
+{
+public:
+ enum Position{
+ PositionBottom,
+ PositionTop,
+ PositionLeft,
+ PositionRight
+ };
+ Q_PROPERTY(Position position READ position NOTIFY positionChanged)
+
+ virtual Position position() const = 0;
+ bool isHorizontal() const { return position() == PositionBottom || position() == PositionTop; }
+
+ virtual QRect globalGometry() const = 0;
+};
+
+#endif // IRAZORPANEL_H
View
136 razorqt-panel/panel/irazorpanelplugin.h
@@ -0,0 +1,136 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Alexander Sokoloff <sokoloff.a@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+
+#ifndef IRAZORPANELPLUGIN_H
+#define IRAZORPANELPLUGIN_H
+
+#include <QtPlugin>
+#include <QtGui/qwindowdefs.h> // For XEvent
+#include <QSettings>
+#include <razorqt/razorplugininfo.h>
+#include "irazorpanel.h"
+
+class QDialog;
+
+struct IRazorPanelPluginStartupInfo
+{
+ IRazorPanel *razorPanel;
+ QSettings *settings;
+ const RazorPluginInfo *desktopFile;
+};
+
+class IRazorPanelPlugin
+{
+public:
+ /**
+ This enum describes the properties of an plugin.
+ **/
+ enum Flag {
+ NoFlags = 0, //! It does not have any properties set.
+ PreferRightAlignment = 1, /*! The plugin is prefer right alignment (for example the clock plugin);
+ otherwise plugin prefer left (like main menu).
+ This flag is used only at the first start, later positions of all
+ plugins saved in a config, and this saved information is used. */
+ HaveConfigDialog = 2 //! The plugin have a configuration dialog.
+ };
+
+ Q_DECLARE_FLAGS(Flags, Flag)
+
+ IRazorPanelPlugin(const IRazorPanelPluginStartupInfo &startupInfo):
+ mSettings(startupInfo.settings),
+ mPanel(startupInfo.razorPanel),
+ mDesktopFile(startupInfo.desktopFile)
+ {}
+
+ virtual ~IRazorPanelPlugin() {}
+
+ /**
+ Returns the plugin flags.
+ The base class implementation returns a NoFlags.
+ **/
+ virtual Flags flags() const { return NoFlags; }
+
+ /**
+ Returns the plugin settings dialog. Reimplement this function if your plugin has it.
+ **/
+ virtual QString themeId() const = 0;
+
+ virtual QWidget *widget() = 0;
+
+
+ /**
+ If you reimplement this function, you get direct access to all X events that the
+ are received from the X server. The events are passed in the event parameter.
+
+ The default implementation do nothing.
+ **/
+ virtual void x11EventFilter(XEvent *event) {}
+
+ /**
+ Returns the plugin settings dialog. Reimplement this function if your plugin has it.
+ The panel takes ownership of the dialog; i.e., it will automatically delete.
+ The default implementation returns 0, no dialog;
+
+ Note that the flags method has to return HaveConfigDialog flag.
+ To save the settings you should use a ready-to-use IRazorPanelPlugin::settings() object.
+
+ **/
+ virtual QDialog *configureDialog() { return 0; }
+
+ /**
+ This function is called when values are changed in the plugin settings.
+ Reimplement this function to your plugin corresponded the new settings.
+
+ The default implementation do nothing.
+ **/
+ virtual void settingsChanged() {}
+
+ IRazorPanel *panel() const { return mPanel; }
+ QSettings *settings() const { return mSettings; }
+ const RazorPluginInfo *desktopFile() const { return mDesktopFile; }
+
+private:
+ QSettings *mSettings;
+ IRazorPanel *mPanel;
+ const RazorPluginInfo *mDesktopFile;
+};
+
+
+
+class IRazorPanelPluginLibrary
+{
+public:
+ virtual ~IRazorPanelPluginLibrary() {}
+ virtual IRazorPanelPlugin* instance(const IRazorPanelPluginStartupInfo &startupInfo) = 0;
+};
+
+
+Q_DECLARE_INTERFACE(IRazorPanelPluginLibrary,
+ "razor-qt.org/Panel/PluginInterface/2.0")
+
+#endif // IRAZORPANELPLUGIN_H
View
299 razorqt-panel/panel/plugin.cpp
@@ -0,0 +1,299 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Alexander Sokoloff <sokoloff.a@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+
+#include "plugin.h"
+#include "irazorpanelplugin.h"
+#include "razorpanel.h"
+#include <QDebug>
+#include <QProcessEnvironment>
+#include <QStringList>
+#include <QDir>
+#include <QFileInfo>
+#include <QPluginLoader>
+#include <QGridLayout>
+#include <QDialog>
+#include <QEvent>
+#include <QMenu>
+
+
+#include <razorqt/razorsettings.h>
+#include <qtxdg/xdgicon.h>
+
+
+/************************************************
+
+ ************************************************/
+Plugin::Plugin(const RazorPluginInfo &desktopFile, const QString &settingsFile, const QString &settingsGroup, RazorPanel *panel) :
+ QFrame(panel),
+ mDesktopFile(desktopFile),
+ mPlugin(0),
+ mPluginLib(0),
+ mPluginWidget(0),
+ mAlignment(AlignLeft),
+ mSettingsGroup(settingsGroup),
+ mPanel(panel)
+{
+
+ mSettings = new RazorSettings(settingsFile, QSettings::IniFormat, this);
+ connect(mSettings, SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
+ mSettings->beginGroup(settingsGroup);
+
+ setWindowTitle(desktopFile.name());
+
+ QStringList dirs;
+ dirs << QProcessEnvironment::systemEnvironment().value("RAZORPANEL_PLUGIN_PATH").split(":");
+ dirs << PLUGIN_DIR;
+
+ QString baseName = QString("lib%1.so").arg(desktopFile.id());
+ bool found = false;
+ foreach(QString dirName, dirs)
+ {
+ QFileInfo fi(QDir(dirName), baseName);
+
+ if (fi.exists())
+ {
+ found = true;
+ if (loadLib(fi.absoluteFilePath()))
+ break;
+ }
+ }
+
+ if (!isLoaded())
+ {
+ if (!found)
+ qWarning() << QString("Plugin %1 not found in the").arg(baseName) << dirs;
+
+ return;
+ }
+
+ setObjectName(mPlugin->themeId());
+ QString s = mSettings->value("alignment").toString();
+
+ // Retrun default value
+ if (s.isEmpty())
+ {
+ mAlignment = (mPlugin->flags().testFlag(IRazorPanelPlugin::PreferRightAlignment)) ?
+ Plugin::AlignRight :
+ Plugin::AlignLeft;
+ }
+ else
+ {
+ mAlignment = (s.toUpper() == "RIGHT") ?
+ Plugin::AlignRight :
+ Plugin::AlignLeft;
+
+ }
+
+ if (mPluginWidget)
+ {
+ QGridLayout* layout = new QGridLayout(this);
+ layout->setSpacing(0);
+ layout->setMargin(0);
+ layout->setContentsMargins(0, 0, 0, 0);
+ setLayout(layout);
+ layout->addWidget(mPluginWidget, 0, 0);
+ }
+}
+
+
+/************************************************
+
+ ************************************************/
+Plugin::~Plugin()
+{
+ delete mPlugin;
+ delete mPluginLib;
+}
+
+
+/************************************************
+
+ ************************************************/
+bool Plugin::loadLib(const QString &libraryName)
+{
+ QPluginLoader loader(libraryName);
+
+
+ if (!loader.load())
+ {
+ qWarning() << loader.errorString();
+ return false;
+ }
+
+ QObject *obj = loader.instance();
+ if (!obj)
+ {
+ qWarning() << loader.errorString();
+ return false;
+ }
+
+ mPluginLib= qobject_cast<IRazorPanelPluginLibrary*>(obj);
+ if (!mPluginLib)
+ {
+ qWarning() << QString("Can't load plugin \"%1\". Plugin is not a IRazorPanelPluginLibrary.").arg(loader.fileName());
+ delete obj;
+ return false;
+ }
+
+ IRazorPanelPluginStartupInfo startupInfo;
+ startupInfo.settings = mSettings;
+ startupInfo.desktopFile = &mDesktopFile;
+ startupInfo.razorPanel = mPanel;
+
+ mPlugin = mPluginLib->instance(startupInfo);
+ if (!mPlugin)
+ {
+ qWarning() << QString("Can't load plugin \"%1\". Plugin can't build IRazorPanelPlugin.").arg(loader.fileName());
+ delete obj;
+ return false;
+ }
+
+ mPluginWidget = mPlugin->widget();
+ this->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
+ return true;
+}
+
+
+/************************************************
+
+ ************************************************/
+void Plugin::settingsChanged()
+{
+ mPlugin->settingsChanged();
+}
+
+
+/************************************************
+
+ ************************************************/
+void Plugin::saveSettings()
+{
+ qDebug() << mSettingsGroup;
+ mSettings->setValue("alignment", (mAlignment == AlignLeft) ? "Left" : "Right");
+ mSettings->setValue("type", mDesktopFile.id());
+ mSettings->sync();
+
+}
+
+
+/************************************************
+
+ ************************************************/
+void Plugin::x11EventFilter(XEvent *event)
+{
+ mPlugin->x11EventFilter(event);
+}
+
+
+/************************************************
+
+ ************************************************/
+bool Plugin::event(QEvent *e)
+{
+ switch (e->type())
+ {
+ case QEvent::ContextMenu:
+ mPanel->showPopupMenu(this);
+ return true;
+
+ default:
+ break;
+ }
+ return QFrame::event(e);
+}
+
+
+/************************************************
+
+ ************************************************/
+QMenu *Plugin::popupMenu() const
+{
+
+ QMenu* menu = new QMenu(windowTitle());
+
+ if (mPlugin->flags().testFlag(IRazorPanelPlugin::HaveConfigDialog))
+ {
+ QAction* configAction = new QAction(tr("Configure"), menu);
+ menu->addAction(configAction);
+ connect(configAction, SIGNAL(triggered()), this, SLOT(showConfigureDialog()));
+ }
+
+ QAction* moveAction = new QAction(XdgIcon::fromTheme("transform-move"), tr("Move"), menu);
+ menu->addAction(moveAction);
+ connect(moveAction, SIGNAL(triggered()), this, SLOT(requestMove()));
+
+ menu->addSeparator();
+
+ QAction* removeAction = new QAction(XdgIcon::fromTheme("dialog-close"), tr("Remove"), menu);
+ menu->addAction(removeAction);
+ connect(removeAction, SIGNAL(triggered()), this, SLOT(requestRemove()));
+
+ return menu;
+}
+
+
+/************************************************
+
+ ************************************************/
+void Plugin::showConfigureDialog()
+{
+ QDialog *dialog =
+ this->findChild<QDialog*>();
+
+ if (!dialog)
+ {
+ dialog = mPlugin->configureDialog();
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ }
+
+ if (!dialog)
+ return;
+
+ dialog->show();
+ dialog->raise();
+ dialog->activateWindow();
+}
+
+
+/************************************************
+
+ ************************************************/
+void Plugin::requestMove()
+{
+ emit move(this);
+}
+
+
+/************************************************
+
+ ************************************************/
+void Plugin::requestRemove()
+{
+ emit remove();
+ deleteLater();
+}
View
93 razorqt-panel/panel/plugin.h
@@ -0,0 +1,93 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Alexander Sokoloff <sokoloff.a@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+#include <QFrame>
+#include <QString>
+#include <razorqt/razorplugininfo.h>
+
+class QSettings;
+class IRazorPanel;
+class IRazorPanelPlugin;
+class IRazorPanelPluginLibrary;
+class RazorPanel;
+class QMenu;
+
+class Plugin : public QFrame
+{
+ Q_OBJECT
+public:
+ enum Alignment {
+ AlignLeft,
+ AlignRight
+ };
+
+
+ explicit Plugin(const RazorPluginInfo &desktopFile, const QString &settingsFile, const QString &settingsGroup, RazorPanel *panel);
+ ~Plugin();
+
+ bool isLoaded() const { return mPlugin != 0; }
+ Alignment alignment() const { return mAlignment; }
+ void setAlignment(Alignment alignment) { mAlignment = alignment; }
+
+ QString settingsGroup() const { return mSettingsGroup; }
+
+ void saveSettings();
+ void x11EventFilter(XEvent* event);
+
+ QMenu* popupMenu() const;
+
+signals:
+ void move(QWidget *widget);
+ void remove();
+
+protected:
+ virtual bool event(QEvent* e);
+
+private:
+ bool loadLib(const QString &libraryName);
+
+ const RazorPluginInfo mDesktopFile;
+ IRazorPanelPlugin *mPlugin;
+ IRazorPanelPluginLibrary *mPluginLib;
+ QWidget *mPluginWidget;
+ Alignment mAlignment;
+ QSettings *mSettings;
+ QString mSettingsGroup;
+ RazorPanel *mPanel;
+
+private slots:
+ void settingsChanged();
+ void showConfigureDialog();
+ void requestMove();
+ void requestRemove();
+};
+
+#endif // PLUGIN_H
View
351 razorqt-panel/panel/razorpanel.cpp
@@ -29,10 +29,11 @@
#include "razorpanel.h"
#include "razorpanel_p.h"
#include "razorpanellimits.h"
-#include "razorpanelplugin.h"
+#include "irazorpanelplugin.h"
#include "razorpanelapplication.h"
#include "razorpanellayout.h"
#include "configpaneldialog.h"
+#include "plugin.h"
#include <razorqt/addplugindialog/addplugindialog.h>
#include <razorqt/razorsettings.h>
#include <razorqt/razorplugininfo.h>
@@ -43,7 +44,7 @@
#include <QtGui/QDesktopWidget>
#include <QtGui/QMenu>
#include <QtGui/QContextMenuEvent>
-
+#include <QtCore/QSet>
#include <qtxdg/xdgicon.h>
#include <razorqt/xfitman.h>
@@ -92,68 +93,47 @@ RazorPanel::RazorPanel(QWidget *parent) :
QFrame(parent),
d_ptr(new RazorPanelPrivate(this))
{
- Q_D(RazorPanel);
- d->init();
-
- setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
- setAttribute(Qt::WA_X11NetWmWindowTypeDock);
- setAttribute(Qt::WA_AlwaysShowToolTips);
- setWindowTitle("Razor Panel");
-
- setObjectName("RazorPanel");
-}
-
-
-/************************************************
-
- ************************************************/
-RazorPanelPrivate::RazorPanelPrivate(RazorPanel* parent):
- QObject(parent),
- q_ptr(parent),
- mScreenNum(0)
-{
// Read command line arguments ..............
// The first argument is config file name.
- mConfigFile = "panel";
+ QString configFile = "panel";
if (qApp->arguments().count() > 1)
{
- mConfigFile = qApp->arguments().at(1);
- if (mConfigFile.endsWith(".conf"))
- mConfigFile.chop(5);
+ configFile = qApp->arguments().at(1);
+ if (configFile.endsWith(".conf"))
+ configFile.chop(5);
}
- mSettings = new RazorSettings("razor-panel/" + mConfigFile, this);
- mLayout = new RazorPanelLayout(QBoxLayout::LeftToRight, parent);
- connect(mLayout, SIGNAL(widgetMoved(QWidget*)), this, SLOT(pluginMoved(QWidget*)));
+ setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
+ setAttribute(Qt::WA_X11NetWmWindowTypeDock);
+ setAttribute(Qt::WA_AlwaysShowToolTips);
+ setWindowTitle("Razor Panel");
+ setObjectName("RazorPanel");
+
+ Q_D(RazorPanel);
- connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(screensChangeds()));
- connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), this, SLOT(screensChangeds()));
- //connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), this, SLOT(screensChangeds()));
+ d->mLayout = new RazorPanelLayout(QBoxLayout::LeftToRight, parent);
+ connect(d->mLayout, SIGNAL(widgetMoved(QWidget*)), d, SLOT(pluginMoved(QWidget*)));
+ setLayout(d->mLayout);
- connect(RazorSettings::globalSettings(), SIGNAL(settingsChanged()), q_ptr, SLOT(update()));
+ connect(QApplication::desktop(), SIGNAL(resized(int)), d_ptr, SLOT(screensChangeds()));
+ connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), d_ptr, SLOT(screensChangeds()));
+ connect(RazorSettings::globalSettings(), SIGNAL(settingsChanged()), this, SLOT(update()));
connect(razorApp, SIGNAL(themeChanged()), this, SLOT(realign()));
-}
+ d->mSettings = new RazorSettings("razor-panel/" + configFile, this);
+ d->readSettings();
-/************************************************
-
- ************************************************/
-void RazorPanelPrivate::screensChangeds()
-{
- if (! canPlacedOn(mScreenNum, mPosition))
- mScreenNum = findAvailableScreen(mPosition);
+ d->loadPlugins();
+ d->reposition();
- reposition();
}
-
/************************************************
************************************************/
-void RazorPanelPrivate::init()
+void RazorPanelPrivate::readSettings()
{
- Q_Q(RazorPanel);
// Read settings ............................
mSettings->beginGroup(CFG_PANEL_GROUP);
mPosition = strToPosition(mSettings->value(CFG_KEY_POSITION).toString(), RazorPanel::PositionBottom);
@@ -164,34 +144,43 @@ void RazorPanelPrivate::init()
mWidth = mSettings->value(CFG_KEY_WIDTH, 100).toInt();
mUseThemeSize = mSettings->value(CFG_KEY_AUTOSIZE, true).toBool();
mSettings->endGroup();
+}
- q->setLayout(mLayout);
- loadPlugins();
- updatePluginsMinSize();
- reposition();
-}
+/************************************************
+ ************************************************/
+RazorPanelPrivate::RazorPanelPrivate(RazorPanel* parent):
+ QObject(parent),
+ q_ptr(parent)
+{
+ mScreenNum = 0;
+ mSpacer = 0;
+}
/************************************************
************************************************/
-RazorPanel::~RazorPanel()
+void RazorPanelPrivate::screensChangeds()
{
- Q_D(RazorPanel);
- d->saveSettings();
- delete d;
+ if (! canPlacedOn(mScreenNum, mPosition))
+ mScreenNum = findAvailableScreen(mPosition);
+
+ reposition();
}
/************************************************
************************************************/
-RazorPanelPrivate::~RazorPanelPrivate()
+RazorPanel::~RazorPanel()
{
- qDeleteAll(mPlugins);
- mSettings->sync();
+ Q_D(RazorPanel);
+ d->saveSettings();
+ qDeleteAll(d->mPlugins);
+ d->mSettings->sync();
+ delete d;
}
@@ -200,24 +189,22 @@ RazorPanelPrivate::~RazorPanelPrivate()
************************************************/
void RazorPanelPrivate::saveSettings()
{
- foreach (RazorPanelPlugin* plugin, mPlugins)
- {
- if (plugin->alignment() == RazorPanelPlugin::AlignLeft)
- plugin->settings().setValue("alignment", "Left");
- else
- plugin->settings().setValue("alignment", "Right");
- }
-
- mSettings->beginGroup(CFG_PANEL_GROUP);
-
+ qDebug() << Q_FUNC_INFO;
QStringList pluginsStr;
+
for (int i=0; i<mLayout->count(); ++i)
{
- RazorPanelPlugin* plugin = qobject_cast<RazorPanelPlugin*>(mLayout->itemAt(i)->widget());
+ qDebug() << "::" << i;
+ Plugin* plugin = qobject_cast<Plugin*>(mLayout->itemAt(i)->widget());
if (plugin)
- pluginsStr << plugin->configId();
+ {
+ plugin->saveSettings();
+ pluginsStr << plugin->settingsGroup();
+ qDebug() << " * " << pluginsStr;
+ }
}
+ mSettings->beginGroup(CFG_PANEL_GROUP);
mSettings->setValue(CFG_KEY_PLUGINS, pluginsStr);
mSettings->endGroup();
mSettings->sync();
@@ -255,7 +242,6 @@ void RazorPanelPrivate::loadPlugins()
continue;
}
-
RazorPluginInfoList list = RazorPluginInfo::search(desktopDirs, "RazorPanel/Plugin", QString("%1.desktop").arg(type));
if( !list.count())
{
@@ -267,12 +253,14 @@ void RazorPanelPrivate::loadPlugins()
}
- QList<RazorPanelPlugin*>::iterator i;
+ QList<Plugin*>::iterator i;
+
// Add left plugins .........................
for (i=mPlugins.begin(); i != mPlugins.end(); ++i)
{
- if ((*i)->alignment() != RazorPanelPlugin::AlignLeft)
+ if ((*i)->alignment() != Plugin::AlignLeft)
break;
+
mLayout->addWidget((*i));
}
@@ -284,45 +272,26 @@ void RazorPanelPrivate::loadPlugins()
{
mLayout->addWidget((*i));
}
+
}
/************************************************
************************************************/
-RazorPanelPlugin* RazorPanelPrivate::loadPlugin(const RazorPluginInfo& pluginInfo, const QString configSection)
+Plugin *RazorPanelPrivate::loadPlugin(const RazorPluginInfo &desktopFile, const QString &settingsGroup)
{
Q_Q(RazorPanel);
+ Plugin *plugin = new Plugin(desktopFile, mSettings->fileName(), settingsGroup, q);
+ if (plugin->isLoaded())
+ {
+ mPlugins.append(plugin);
+ connect(plugin, SIGNAL(move(QWidget*)), mLayout, SLOT(startMoveWidget(QWidget*)));
+ connect(plugin, SIGNAL(remove()), this, SLOT(pluginRemoved()));
+ return plugin;
+ }
- QLibrary* lib = 0;
-
- if (getenv("RAZORQT_PANEL_PLUGINS_SO_DIR"))
- lib = pluginInfo.loadLibrary(getenv("RAZORQT_PANEL_PLUGINS_SO_DIR"));
-
- if (!lib)
- lib = pluginInfo.loadLibrary(PLUGIN_DIR);
-
- if (!lib)
- return 0;
-
-
- PluginInitFunction initFunc = (PluginInitFunction) lib->resolve("init");
-
- if (!initFunc)
- return 0;
-
- RazorPanelPluginStartInfo startInfo(mSettings, configSection, q, pluginInfo);
- RazorPanelPlugin* plugin = initFunc(&startInfo, q);
- if (!plugin)
- return 0;
-
- connect(q, SIGNAL(layoutDirectionChanged(QBoxLayout::Direction)),
- plugin, SLOT(layoutDirectionChanged(QBoxLayout::Direction)));
- connect(plugin, SIGNAL(move()), SLOT(onMovePlugin()));
- connect(plugin, SIGNAL(remove()), SLOT(onRemovePlugin()));
-
- mPlugins.append(plugin);
- return plugin;
+ return 0;
}
@@ -531,21 +500,21 @@ int RazorPanelPrivate::findAvailableScreen(RazorPanel::Position position)
************************************************/
void RazorPanelPrivate::pluginMoved(QWidget* pluginWidget)
{
- RazorPanelPlugin* plugin = qobject_cast<RazorPanelPlugin*>(pluginWidget);
+ Plugin* plugin = qobject_cast<Plugin*>(pluginWidget);
if (!plugin)
return;
for (int i=0; i<mLayout->count(); ++i)
{
if (mLayout->itemAt(i) == mSpacer)
{
- plugin->setAlignment(RazorPanelPlugin::AlignRight);
+ plugin->setAlignment(Plugin::AlignRight);
break;
}
if (mLayout->itemAt(i)->widget() == plugin)
{
- plugin->setAlignment(RazorPanelPlugin::AlignLeft);
+ plugin->setAlignment(Plugin::AlignLeft);
break;
}
}
@@ -604,79 +573,62 @@ void RazorPanelPrivate::updateSize(int height, int width, bool percent, RazorPan
mWidthInPercents = percent;
mAlignment = alignment;
mUseThemeSize = useThemeSize;
-
- updatePluginsMinSize();
realign();
}
+
/************************************************
************************************************/
-void RazorPanelPrivate::updatePluginsMinSize()
+QString RazorPanelPrivate::findNewPluginSettingsGroup(const QString &pluginType) const
{
- Q_Q(RazorPanel);
- if (mUseThemeSize)
- {
- foreach (RazorPanelPlugin *plugin, mPlugins)
- {
- plugin->setMinimumSize(QSize(0,0));
- }
+ QSet<QString> loadedPlugins = QSet<QString>::fromList(mSettings->value(CFG_FULLKEY_PLUGINS).toStringList());
- mHeight = -1;
- }
- else
+ QStringList groups = mSettings->childGroups();
+ groups.sort();
+
+ // Search free section name .................
+ foreach(const QString &group, groups)
{
- foreach (RazorPanelPlugin *plugin, mPlugins)
+ if (!loadedPlugins.contains(group))
{
- plugin->setMinimumSize(QSize(1,1));
+ if (mSettings->value(group + "/type") == pluginType)
+ {
+ return group;
+ }
}
+ }
- if (q->isHorizontal())
- {
- q->setMaximumHeight(mHeight);
- }
- else
- {
- q->setMaximumWidth(mHeight);
- }
+ // Generate new section name ................
+ for (int i=2; true; ++i)
+ {
+ if (!groups.contains(QString("%1%2").arg(pluginType).arg(i)))
+ return QString("%1%2").arg(pluginType).arg(i);
}
}
/************************************************
************************************************/
-void RazorPanelPrivate::addPlugin(const RazorPluginInfo &pluginInfo)
+void RazorPanelPrivate::addPlugin(const RazorPluginInfo &desktopFile)
{
Q_Q(RazorPanel);
- QString sectionName = pluginInfo.id();
- QStringList groups = mSettings->childGroups();
+ QString settingsGroup = findNewPluginSettingsGroup(desktopFile.id());
+ Plugin *plugin= loadPlugin(desktopFile, settingsGroup);
- if (groups.contains(sectionName))
- {
- for (int i=2; true; ++i)
- {
- sectionName = QString("%1%2").arg(pluginInfo.id()).arg(i);
- if (!groups.contains(sectionName))
- break;
- }
- }
-
- RazorPanelPlugin* plugin = loadPlugin(pluginInfo, sectionName);
if (!plugin)
return;
- mSettings->setValue(QString("%1/type").arg(sectionName), pluginInfo.id());
-
- if (plugin->flags().testFlag(RazorPanelPlugin::PreferRightAlignment))
- mLayout->addWidget(plugin);
- else
+ if (plugin->alignment() == Plugin::AlignLeft)
mLayout->insertWidget(0, plugin);
+ else
+ mLayout->addWidget(plugin);
- realign();
+// realign();
+// q->adjustSize();
saveSettings();
- q->adjustSize();
}
@@ -698,7 +650,7 @@ void RazorPanel::show()
RazorPanel::Position RazorPanel::position() const
{
Q_D(const RazorPanel);
- return d->position();
+ return d->mPosition;
}
RazorPanel::Orientation RazorPanel::orientation() const
@@ -721,7 +673,7 @@ RazorPanel::Orientation RazorPanel::orientation() const
void RazorPanel::x11EventFilter(XEvent* event)
{
Q_D(RazorPanel);
- foreach (RazorPanelPlugin* plugin, d->mPlugins)
+ foreach (Plugin* plugin, d->mPlugins)
{
plugin->x11EventFilter(event);
}
@@ -731,6 +683,15 @@ void RazorPanel::x11EventFilter(XEvent* event)
/************************************************
************************************************/
+QRect RazorPanel::globalGometry() const
+{
+ return QRect(mapToGlobal(QPoint(0, 0)), this->size());
+}
+
+
+/************************************************
+
+ ************************************************/
bool RazorPanel::event(QEvent* e)
{
Q_D(RazorPanel);
@@ -754,7 +715,7 @@ bool RazorPanel::event(QEvent* e)
/************************************************
************************************************/
-void RazorPanel::showPopupMenu(RazorPanelPlugin *plugin)
+void RazorPanel::showPopupMenu(Plugin *plugin)
{
Q_D(RazorPanel);
@@ -815,63 +776,15 @@ void RazorPanel::showPopupMenu(RazorPanelPlugin *plugin)
/************************************************
************************************************/
-void RazorPanelPrivate::onMovePlugin()
+void RazorPanelPrivate::pluginRemoved()
{
- RazorPanelPlugin* plugin;
- PluginAction* a = qobject_cast<PluginAction*>(sender());
- if (a)
+ Plugin *p = qobject_cast<Plugin*>(sender());
+ if (p)
{
- plugin = a->plugin();
+ mLayout->removeWidget(p);
+ mPlugins.removeAll(p);
+ saveSettings();
}
- else
- {
- plugin = qobject_cast<RazorPanelPlugin*>(sender());
- if (!plugin)
- return;
- }
-
- CursorAnimation *cursorAnimation = new CursorAnimation(plugin);
- connect(cursorAnimation, SIGNAL(finished()), SLOT(startMoveWidget()));
- cursorAnimation->setEasingCurve(QEasingCurve::InOutQuad);
- cursorAnimation->setDuration(150);
- cursorAnimation->setStartValue(QCursor::pos());
- cursorAnimation->setEndValue(plugin->mapToGlobal(plugin->rect().center()));
- cursorAnimation->start(QAbstractAnimation::DeleteWhenStopped);
-}
-
-void RazorPanelPrivate::startMoveWidget()
-{
- CursorAnimation* a = qobject_cast<CursorAnimation*>(sender());
- if (!a)
- return;
- mLayout->startMoveWidget(qobject_cast<QWidget *>(a->parent()));
-}
-
-/************************************************
-
- ************************************************/
-void RazorPanelPrivate::onRemovePlugin()
-{
- Q_Q(RazorPanel);
-
- RazorPanelPlugin* plugin;
- PluginAction* a = qobject_cast<PluginAction*>(sender());
- if (a)
- {
- plugin = a->plugin();
- }
- else
- {
- plugin = qobject_cast<RazorPanelPlugin*>(sender());
- if (!plugin)
- return;
- }
-
- mSettings->remove(plugin->configId());
- mPlugins.removeAll(plugin);
- delete plugin;
- saveSettings();
- q->adjustSize();
}
@@ -891,15 +804,15 @@ void RazorPanelPrivate::switchPosition(int screenNum, RazorPanel::Position posit
void RazorPanelPrivate::reposition()
{
Q_Q(RazorPanel);
-
+/*
QRect screen = QApplication::desktop()->screenGeometry(mScreenNum);
if (q->isHorizontal())
mLayout->setDirection(QBoxLayout::LeftToRight);
else
mLayout->setDirection(QBoxLayout::TopToBottom);
- foreach (RazorPanelPlugin* plugin, mPlugins)
+ foreach (Plugin* plugin, mPlugins)
{
plugin->updateSizePolicy();
}
@@ -929,29 +842,11 @@ void RazorPanelPrivate::reposition()
q->setMaximumHeight(screen.height());
}
}
-
+*/
realign();
}
-/************************************************
-
- ************************************************/
-CursorAnimation::CursorAnimation(QObject *parent):
- QVariantAnimation(parent)
-{
-}
-
-
-/************************************************
-
- ************************************************/
-void CursorAnimation::updateCurrentValue(const QVariant &value)
-{
- QCursor::setPos(value.toPoint());
-}
-
-
static const char POPUPMENU_TITLE[] = "POPUP_MENU_TITLE_OBJECT_NAME";
/************************************************
@@ -1019,3 +914,5 @@ void PopupMenu::keyPressEvent(QKeyEvent* e)
QMenu::keyPressEvent(e);
}
+
+
View
20 razorqt-panel/panel/razorpanel.h
@@ -32,29 +32,24 @@
#include <QtGui/QFrame>
#include <QtCore/QString>
#include <QtGui/QBoxLayout>
+#include "irazorpanel.h"
class QMenu;
class RazorPanelPrivate;
class RazorPanelPlugin;
+class Plugin;
/*! \brief The RazorPanel class provides a single razor-panel.
*/
-class RazorPanel : public QFrame
+class RazorPanel : public QFrame, public IRazorPanel
{
Q_OBJECT
- Q_PROPERTY(Position position READ position NOTIFY positionChanged)
Q_PROPERTY(Orientation orientation READ orientation)
Q_ENUMS(Position)
Q_ENUMS(Orientation)
friend class RazorPanelPlugin;
public:
- enum Position{
- PositionBottom,
- PositionTop,
- PositionLeft,
- PositionRight
- };
enum Alignment {
AlignmentLeft = -1,
@@ -70,13 +65,16 @@ class RazorPanel : public QFrame
RazorPanel(QWidget *parent = 0);
virtual ~RazorPanel();
- Position position() const ;
- bool isHorizontal() const { return position() == PositionBottom || position() == PositionTop; }
+ virtual Position position() const;
Orientation orientation() const;
- void showPopupMenu(RazorPanelPlugin *plugin = 0);
+ void showPopupMenu(Plugin *plugin = 0);
void x11EventFilter(XEvent* event);
+ // IRazorPanel .........................
+ virtual QRect globalGometry() const;
+
+
public slots:
void show();
View
57 razorqt-panel/panel/razorpanel_p.h
@@ -31,12 +31,12 @@
#define RAZORPANEL_P_H
#include "razorpanel.h"
-#include "razorpanelplugin.h"
#include <razorqt/razorplugininfo.h>
#include <QtGui/QAction>
-#include <QtCore/QVariantAnimation>
#include <QtCore/QEvent>
#include <QtGui/QMenu>
+#include <QList>
+#include "plugin.h"
class QActionGroup;
class QLayoutItem;
@@ -48,18 +48,28 @@ class RazorPanelPrivate: QObject {
Q_OBJECT
public:
RazorPanelPrivate(RazorPanel* parent);
- virtual ~RazorPanelPrivate();
- void init();
-
- RazorPanel::Position position() const { return mPosition; }
-
- QList<RazorPanelPlugin*>& plugins() { return mPlugins; }
static bool canPlacedOn(int screenNum, RazorPanel::Position position);
static RazorPanel::Position strToPosition(const QString &str, RazorPanel::Position defaultValue);
static QString positionToStr(RazorPanel::Position position);
+ void readSettings();
void saveSettings();
+ void loadPlugins();
+ Plugin *loadPlugin(const RazorPluginInfo &desktopFile, const QString &settingsGroup);
+ QString findNewPluginSettingsGroup(const QString &pluginType) const;
+
+ QList<Plugin*> mPlugins;
+ RazorPanel::Position mPosition;
+ RazorPanel::Alignment mAlignment;
+ int mHeight;
+ int mWidth;
+ bool mWidthInPercents;
+ int mScreenNum;
+ RazorSettings* mSettings;
+ RazorPanelLayout* mLayout;
+ QLayoutItem* mSpacer;
+ bool mUseThemeSize;
public slots:
void realign();
@@ -69,35 +79,19 @@ public slots:
void screensChangeds();
void showAddPluginDialog();
void showConfigPanelDialog();
- void addPlugin(const RazorPluginInfo &pluginInfo);
- void onRemovePlugin();
- void onMovePlugin();
- void startMoveWidget();
+ void addPlugin(const RazorPluginInfo &desktopFile);
+ void pluginRemoved();
void updateSize(int height, int width, bool percent, RazorPanel::Alignment alignment, bool useThemeSize);
private:
- void loadPlugins();
- RazorPanelPlugin* loadPlugin(const RazorPluginInfo& pluginInfo, const QString configSection);
+
void reTheme();
int findAvailableScreen(RazorPanel::Position position);
QStringList pluginDesktopDirs();
RazorPanel* const q_ptr;
Q_DECLARE_PUBLIC(RazorPanel)
- RazorPanel::Position mPosition;
- RazorPanel::Alignment mAlignment;
- int mHeight;
- int mWidth;
- bool mWidthInPercents;
- int mScreenNum;
- QString mConfigFile;
- RazorSettings* mSettings;
- QList<RazorPanelPlugin*> mPlugins;
- RazorPanelLayout* mLayout;
- QLayoutItem* mSpacer;
- bool mUseThemeSize;
- void updatePluginsMinSize();
};
@@ -116,15 +110,6 @@ class PluginAction: public QAction
RazorPanelPlugin* mPlugin;
};
-class CursorAnimation: public QVariantAnimation
-{
- Q_OBJECT
-
-public:
- CursorAnimation(QObject *parent);
-
- void updateCurrentValue(const QVariant &value);
-};
class PopupMenu: public QMenu
View
40 razorqt-panel/panel/razorpanellayout.cpp
@@ -74,6 +74,9 @@ class ItemMoveAnimation : public QVariantAnimation
#endif
+/************************************************
+
+ ************************************************/
class MoveProcItem
{
public:
@@ -100,18 +103,26 @@ MoveProcessor::MoveProcessor(RazorPanelLayout* layout, QWidget* movedWidget):
mWidget(movedWidget),
mLayout(layout)
{
+}
+
+
+/************************************************
+
+ ************************************************/
+void MoveProcessor::start()
+{
mWidgetPlace = mWidget->geometry();
mOffset = QCursor::pos() - mWidget->pos();
- mIndex = layout->indexOf(movedWidget);
+ mIndex = mLayout->indexOf(mWidget);
mWidget->raise();
- for (int i=0; i<layout->count(); ++i)
+ for (int i=0; i<mLayout->count(); ++i)
{
if (i != mIndex)
- mItems.append(new MoveProcItem(layout->itemAt(i)));
+ mItems.append(new MoveProcItem(mLayout->itemAt(i)));
}
- QBoxLayout::Direction dir = layout->direction();
+ QBoxLayout::Direction dir = mLayout->direction();
mHoriz = (dir == QBoxLayout::LeftToRight || dir == QBoxLayout::RightToLeft);
setMouseTracking(true);
@@ -120,7 +131,7 @@ MoveProcessor::MoveProcessor(RazorPanelLayout* layout, QWidget* movedWidget):
if (mHoriz) this->grabMouse(Qt::SizeHorCursor);
else this->grabMouse(Qt::SizeVerCursor);
- layout->setEnabled(false);
+ mLayout->setEnabled(false);
}
@@ -293,7 +304,7 @@ void MoveProcessor::finished()
mLayout->activate();
mLayout->update();
emit widgetMoved(mWidget);
- delete this;
+ deleteLater();
}
@@ -367,7 +378,7 @@ void MoveProcItem::move(QPoint topLeft)
************************************************/
RazorPanelLayout::RazorPanelLayout(Direction dir, QWidget * parent):
- QBoxLayout(dir, parent)
+ QBoxLayout(dir, parent)
{
setContentsMargins(0, 0, 0, 0);
setSpacing(0);
@@ -388,8 +399,19 @@ RazorPanelLayout::~RazorPanelLayout()
************************************************/
void RazorPanelLayout::startMoveWidget(QWidget* widget)
{
- MoveProcessor* mp = new MoveProcessor(this, widget);
- connect(mp, SIGNAL(widgetMoved(QWidget*)), this, SIGNAL(widgetMoved(QWidget*)));
+ // We have not memoryleaks there.
+ // The processor and animation will be automatically deleted when stopped.
+ MoveProcessor *moveProcessor = new MoveProcessor(this, widget);
+ connect(moveProcessor, SIGNAL(widgetMoved(QWidget*)), this, SIGNAL(widgetMoved(QWidget*)));
+
+ CursorAnimation *cursorAnimation = new CursorAnimation();
+ connect(cursorAnimation, SIGNAL(finished()), moveProcessor, SLOT(start()));
+ cursorAnimation->setEasingCurve(QEasingCurve::InOutQuad);
+ cursorAnimation->setDuration(150);
+
+ cursorAnimation->setStartValue(QCursor::pos());
+ cursorAnimation->setEndValue(widget->mapToGlobal(widget->rect().center()));
+ cursorAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
View
19 razorqt-panel/panel/razorpanellayout.h
@@ -32,10 +32,13 @@
#include <QtGui/QBoxLayout>
#include <QtCore/QList>
#include <QtGui/QWidget>
+#include <QtCore/QVariantAnimation>
class MoveInfo;
class QMouseEvent;
class QEvent;
+class CursorAnimation;
+class MoveProcessor;
class RazorPanelLayout : public QBoxLayout
{
@@ -46,13 +49,13 @@ class RazorPanelLayout : public QBoxLayout
RazorPanelLayout(Direction dir, QWidget* parent=0);
virtual ~RazorPanelLayout();
- void startMoveWidget(QWidget* widget);
-
QSize sizeHint() const;
+public slots:
+ void startMoveWidget(QWidget* widget);
+
signals:
void widgetMoved(QWidget* movedWidget);
-
};
class MoveProcItem;
@@ -64,6 +67,9 @@ class MoveProcessor: public QWidget
explicit MoveProcessor(RazorPanelLayout* layout, QWidget* movedWidget);
~MoveProcessor();
+public slots:
+ void start();
+
signals:
void widgetMoved(QWidget* movedWidget);
@@ -87,4 +93,11 @@ private slots:
void finished();
};
+class CursorAnimation: public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ void updateCurrentValue(const QVariant &value) { QCursor::setPos(value.toPoint()); }
+};
+
#endif // RAZORPANELLAYOUT_H
View
444 razorqt-panel/panel/razorpanelplugin.cpp
@@ -1,444 +0,0 @@
-/* BEGIN_COMMON_COPYRIGHT_HEADER
- * (c)LGPL2+
- *
- * Razor - a lightweight, Qt based, desktop toolset
- * http://razor-qt.org
- *
- * Copyright: 2010-2011 Razor team
- * Authors:
- * Alexander Sokoloff <sokoloff.a@gmail.com>
- *
- * This program or library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- *
- * END_COMMON_COPYRIGHT_HEADER */
-
-
-//#include <QStyleOptionToolBar>
-
-#include "razorpanelplugin.h"
-#include "razorpanelplugin_p.h"
-#include "razorpanellayout.h"
-#include <razorqt/razorplugininfo.h>
-#include <razorqt/razorsettings.h>
-
-#include <QStyleOptionToolBar>
-#include <QtGui/QPainter>
-#include <QtGui/QToolTip>
-#include <QtCore/QDebug>
-#include <QtCore/QEvent>
-#include <QtGui/QMouseEvent>
-#include <QtGui/QMenu>
-#include <qtxdg/xdgicon.h>
-#include <QtCore/QMetaEnum>
-#include <QtCore/QTranslator>
-
-
-/************************************************
-
- ************************************************/
-RazorPanelPlugin::RazorPanelPlugin(const RazorPanelPluginStartInfo* startInfo, QWidget* parent):
- QFrame(parent),
- d_ptr(new RazorPanelPluginPrivate(startInfo, this))
-{
-
-}
-
-
-/************************************************
-
- ************************************************/
-RazorPanelPluginPrivate::RazorPanelPluginPrivate(const RazorPanelPluginStartInfo* startInfo, RazorPanelPlugin* parent):
- QObject(parent),
- q_ptr(parent),
- mSettings(new RazorSettings(startInfo->settings, startInfo->configSection, this)),
- mConfigId(startInfo->configSection),
- mAlignmentCached(false),
- mMovable(false),
- mPanel(startInfo->panel)
-{
- Q_Q(RazorPanelPlugin);
-
- q->setMinimumSize(1, 1);
-
- connect(mSettings, SIGNAL(settingsChanged()), q, SLOT(settingsChanged()));
-
- q->setWindowTitle(startInfo->pluginInfo.name());
- QBoxLayout* layout = new QBoxLayout(mPanel->isHorizontal() ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom, q);
- layout->setSpacing(0);
- layout->setMargin(0);
- layout->setContentsMargins(0, 0, 0, 0);
- q->setLayout(layout);
- q->settingsChanged();
-}
-
-
-/************************************************
-
- ************************************************/
-RazorPanelPlugin::~RazorPanelPlugin()
-{
-}
-
-
-/************************************************
-
- ************************************************/
-RazorPanelPluginPrivate::~RazorPanelPluginPrivate()
-{
-}
-
-
-/************************************************
-
- ************************************************/
-QSettings& RazorPanelPlugin::settings() const
-{
- Q_D(const RazorPanelPlugin);
- return d->settings();
-}
-
-
-/************************************************
-
- ************************************************/
-RazorPanel* RazorPanelPlugin::panel() const
-{
- Q_D(const RazorPanelPlugin);
- return d->panel();
-}
-
-
-/************************************************
-
- ************************************************/
-QMenu* RazorPanelPlugin::popupMenu() const
-{
-
- QMenu* menu = new QMenu(windowTitle());
- //menu->setIcon(windowIcon());
-
- if (flags().testFlag(RazorPanelPlugin::HaveConfigDialog))
- {
- QAction* configAction = new QAction(tr("Configure"), menu);
- menu->addAction(configAction);
- connect(configAction, SIGNAL(triggered()), this, SLOT(showConfigureDialog()));
- }
-
- QAction* moveAction = new QAction(XdgIcon::fromTheme("transform-move"), tr("Move"), menu);
- menu->addAction(moveAction);
- connect(moveAction, SIGNAL(triggered()), this, SLOT(requestMove()));
-
- menu->addSeparator();
-
- QAction* removeAction = new QAction(XdgIcon::fromTheme("dialog-close"), tr("Remove"), menu);
- menu->addAction(removeAction);
- connect(removeAction, SIGNAL(triggered()), this, SLOT(requestRemove()));
-
- return menu;
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::requestMove()
-{
- emit move();
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::requestRemove()
-{
- emit remove();
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::addWidget(QWidget* widget)
-{
- Q_D(RazorPanelPlugin);
- d->addWidget(widget);
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPluginPrivate::addWidget(QWidget* widget)
-{
- Q_Q(RazorPanelPlugin);
- q->layout()->addWidget(widget);
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::layoutDirectionChanged(QBoxLayout::Direction direction)
-{
- Q_D(RazorPanelPlugin);
- d->layoutDirectionChanged(direction);
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPluginPrivate::layoutDirectionChanged(QBoxLayout::Direction direction)
-{
- Q_Q(RazorPanelPlugin);
- QBoxLayout* layout = qobject_cast<QBoxLayout*>(q->layout());
- if (layout)
- layout->setDirection(direction);
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::updateStyleSheet()
-{
- Q_D(RazorPanelPlugin);
- d->updateStyleSheet();
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPluginPrivate::updateStyleSheet()
-{
- Q_Q(RazorPanelPlugin);
- q->style()->unpolish(q);
- q->style()->polish(q);
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPluginPrivate::initStyleOption(QStyleOptionToolBar *option) const
-{
- Q_Q(const RazorPanelPlugin);
- option->initFrom(q);
- option->state |= QStyle::State_Horizontal;
- if (mMovable)
- option->features = QStyleOptionToolBar::Movable;
-}
-
-
-/************************************************
-
- ************************************************/
-QRect RazorPanelPluginPrivate::handleRect()
-{
- Q_Q(RazorPanelPlugin);
- QStyleOptionToolBar opt;
- initStyleOption(&opt);
-
- return q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q);
-}
-
-
-/************************************************
-
- ************************************************/
-bool RazorPanelPlugin::isMovable() const
-{
- Q_D(const RazorPanelPlugin);
- return d->isMovable();
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::setMovable(bool movable)
-{
- Q_D(RazorPanelPlugin);
- d->setMovable(movable);
- emit movableChanged(d->isMovable());
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPluginPrivate::setMovable(bool movable)
-{
- if (mMovable == movable)
- return;
-
- Q_Q(RazorPanelPlugin);
- mMovable = movable;
-
- QMargins m = q->contentsMargins();
-
- if (movable)
- m.setLeft(m.left() + handleRect().width());
- else
- m.setLeft(m.left() - handleRect().width());
-
- q->setContentsMargins(m);
-
- updateStyleSheet();
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::x11EventFilter(XEvent* event)
-{
- Q_UNUSED(event)
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::paintEvent(QPaintEvent* event)
-{
- Q_D(RazorPanelPlugin);
- d->paintEvent(event);
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPluginPrivate::paintEvent(QPaintEvent* event)
-{
- Q_Q(RazorPanelPlugin);
-
- if (mMovable)
- {
- QPainter p(q);
- QStyle *style = q->style();
- QStyleOptionToolBar opt;
- initStyleOption(&opt);
-
- opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, q);
- if (opt.rect.isValid())
- style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, q);
- }
-}
-
-
-/************************************************
-
- ************************************************/
-RazorPanelPlugin::Alignment RazorPanelPlugin::alignment() const
-{
- Q_D(const RazorPanelPlugin);
- return d->alignment();
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::updateSizePolicy()
-{
- if (panel()->isHorizontal())
- setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
- else
- setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
-}
-
-
-/************************************************
-
- ************************************************/
-RazorPanelPlugin::Alignment RazorPanelPluginPrivate::alignment() const
-{
- if (!mAlignmentCached)
- {
- Q_Q(const RazorPanelPlugin);
- QString s = settings().value("alignment").toString();
-
- // Retrun default value
- if (s.isEmpty())
- {
- mAlignment = (q->flags().testFlag(RazorPanelPlugin::PreferRightAlignment)) ?
- RazorPanelPlugin::AlignRight :
- RazorPanelPlugin::AlignLeft;
- }
- else
- mAlignment = (s.toUpper() == "RIGHT") ?
- RazorPanelPlugin::AlignRight :
- RazorPanelPlugin::AlignLeft;
-
- mAlignmentCached = true;
- }
-
- return mAlignment;
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPlugin::setAlignment(Alignment alignment)
-{
- Q_D(RazorPanelPlugin);
- d->setAlignment(alignment);
- emit alignmentChanged();
-}
-
-
-/************************************************
-
- ************************************************/
-void RazorPanelPluginPrivate::setAlignment(RazorPanelPlugin::Alignment alignment)
-{
- mAlignment = alignment;
- updateStyleSheet();
-}
-
-
-/************************************************
-
- ************************************************/
-QString RazorPanelPlugin::configId() const
-{
- Q_D(const RazorPanelPlugin);
- return d->configId();
-}
-
-bool RazorPanelPlugin::event(QEvent *e)
-{
- Q_D(const RazorPanelPlugin);
- switch (e->type())
- {
- case QEvent::ContextMenu:
- d->mPanel->showPopupMenu(this);
- return true;
- break;
-
- default:
- break;
- }
- return QFrame::event(e);
-}
-
-