Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
Razor-panel: New plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
SokoloffA committed Oct 26, 2012
1 parent bbe7898 commit 46657fc
Show file tree
Hide file tree
Showing 28 changed files with 1,114 additions and 1,192 deletions.
83 changes: 37 additions & 46 deletions libraries/razorqt/powermanager.cpp
Expand Up @@ -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."));
}


Expand All @@ -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);
Expand Down Expand Up @@ -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."));
}
4 changes: 1 addition & 3 deletions libraries/razorqt/powermanager.h
Expand Up @@ -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();
Expand All @@ -56,7 +55,6 @@ public slots:

private:
RazorPower * m_power;
QWidget * m_parentWidget;

private slots:
void hibernateFailed();
Expand Down
19 changes: 19 additions & 0 deletions libraries/razorqt/razorsettings.cpp
Expand Up @@ -105,6 +105,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()));
}


/************************************************
************************************************/
Expand Down
1 change: 1 addition & 0 deletions libraries/razorqt/razorsettings.h
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion libraries/razorqxt/qxtglobalshortcut.cpp
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion libraries/razorqxt/qxtglobalshortcut_mac.cpp
Expand Up @@ -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;
}

Expand Down
38 changes: 22 additions & 16 deletions razorqt-panel/CMakeLists.txt
Expand Up @@ -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)
# *******************************************************************


Expand Down Expand Up @@ -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})

Expand Down
23 changes: 15 additions & 8 deletions razorqt-panel/panel/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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}
)
Expand All @@ -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)
50 changes: 50 additions & 0 deletions 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

0 comments on commit 46657fc

Please sign in to comment.