-
-
Save shadeslayer/7af916895bdea2f9bc40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright © 2011 Rohan Garg <rohan16garg@gmail.com> | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License as | |
published by the Free Software Foundation; either version 2 of | |
the License or (at your option) version 3 or any later version | |
accepted by the membership of KDE e.V. (or its successor approved | |
by the membership of KDE e.V.), which shall act as a proxy | |
defined in Section 14 of version 3 of the license. | |
This program 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 General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
#include "synqtray.h" | |
#include "server_interface.h" | |
#include "synqjob.h" | |
#include <KMenu> | |
#include <KLocalizedString> | |
#include <KIcon> | |
#include <KCModuleInfo> | |
#include <KAction> | |
#include <KSettings/Dialog> | |
synqTray::synqTray(QWidget *parent) : KStatusNotifierItem(parent) | |
{ | |
syncevolution_qt_dbus_register_types(); | |
m_server = new OrgSyncevolutionServerInterface(staticInterfaceName(), "/org/syncevolution/Server", QDBusConnection::sessionBus(), this); | |
if (m_server->isValid()) { | |
qDebug() << "Server is valid"; | |
m_menu = contextMenu(); | |
m_menu->clear(); | |
addMenuItems(); | |
setIconByName("view-refresh"); | |
connect(m_server, SIGNAL(ConfigChanged()), SLOT(updateMenu())); | |
} | |
} | |
synqTray::~synqTray() | |
{ | |
m_server->Detach(); | |
} | |
void synqTray::addMenuItems() | |
{ | |
qDebug() << "Adding menu items"; | |
m_server->Attach(); | |
QStringList list = m_server->GetConfigs(false); | |
m_menu->setTitle(i18n("Choose a config to sync ..")); | |
//FIXME: Fix i18n calls over here | |
foreach(const QString & tempString, list) { | |
KAction *syncAction = new KAction(KIcon("view-refresh"), tempString, m_menu); | |
m_menu->addAction(syncAction); | |
connect(syncAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), SLOT(startSync(Qt::MouseButtons,Qt::KeyboardModifiers))); | |
} | |
m_menu->addSeparator(); | |
KAction *showKCM = new KAction(KIcon("configure"), i18n("Configure Accounts ..."), m_menu); | |
m_menu->addAction(showKCM); | |
connect(showKCM, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), SLOT(showSettingsKCM(Qt::MouseButtons,Qt::KeyboardModifiers))); | |
} | |
void synqTray::updateMenu() | |
{ | |
m_menu->clear(); | |
addMenuItems(); | |
} | |
void synqTray::startSync(Qt::MouseButtons,Qt::KeyboardModifiers) | |
{ | |
KAction *action = qobject_cast<KAction*>(sender()); | |
synqJob *job = new synqJob(m_menu->actions().indexOf(action), this); | |
job->start(); | |
} | |
void synqTray::showSettingsKCM(Qt::MouseButtons,Qt::KeyboardModifiers) | |
{ | |
KSettings::Dialog *dialog = new KSettings::Dialog(m_menu); | |
dialog->addModule("synq-config"); | |
dialog->setAttribute(Qt::WA_DeleteOnClose); | |
dialog->exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright © 2011 Rohan Garg <rohan16garg@gmail.com> | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License as | |
published by the Free Software Foundation; either version 2 of | |
the License or (at your option) version 3 or any later version | |
accepted by the membership of KDE e.V. (or its successor approved | |
by the membership of KDE e.V.), which shall act as a proxy | |
defined in Section 14 of version 3 of the license. | |
This program 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 General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
#ifndef SYNQTRAY_H | |
#define SYNQTRAY_H | |
#include "dbustypes.h" | |
#include <KStatusNotifierItem> | |
class KMenu; | |
class QAction; | |
class OrgSyncevolutionServerInterface; | |
class synqTray : public KStatusNotifierItem | |
{ | |
public: | |
synqTray(QWidget *parent = 0); | |
~synqTray(); | |
/** | |
* | |
* Method to return DBus server path | |
*/ | |
static inline const char *staticInterfaceName() { | |
return "org.syncevolution"; | |
} | |
private: | |
OrgSyncevolutionServerInterface *m_server; | |
KMenu *m_menu; | |
void addMenuItems(); | |
private slots: | |
void updateMenu(); | |
void startSync(Qt::MouseButtons, Qt::KeyboardModifiers); | |
void showSettingsKCM(Qt::MouseButtons, Qt::KeyboardModifiers); | |
}; | |
#endif // SYNQTRAY_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment