summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Klapetek <martin.klapetek@gmail.com>2011-07-13 15:46:54 (GMT)
committerMartin Klapetek <martin.klapetek@gmail.com>2011-07-13 15:50:35 (GMT)
commitd175fb4c746cfe564b515fb37bf0c0637183e9f8 (patch)
tree54f762832d06c9b3ab42b4e02e07999da48cf496
parent8bd313dc7cd41d57ad9ef9e7088aa178b5c45972 (diff)
downloadkde-telepathy-contact-list-d175fb4c746cfe564b515fb37bf0c0637183e9f8.tar.gz
kde-telepathy-contact-list-d175fb4c746cfe564b515fb37bf0c0637183e9f8.tar.xz
Check for Presence Plasmoid over D-Bus and warn user if the plasmoid is not active.
CCBUG: 270675 REVIEW: 101918 Reviewed-by: David Edmundson
-rw-r--r--main-widget.cpp84
-rw-r--r--main-widget.h4
2 files changed, 85 insertions, 3 deletions
diff --git a/main-widget.cpp b/main-widget.cpp
index 0c676a0..dcc42b8 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -806,7 +806,7 @@ void MainWidget::onCustomContextMenuRequested(const QPoint &pos)
QStringList groupList;
QList<Tp::AccountPtr> accounts = m_accountManager->allAccounts();
- foreach (const Tp::AccountPtr account, accounts) {
+ foreach (const Tp::AccountPtr &account, accounts) {
if (!account->connection().isNull()) {
groupList.append(account->connection()->contactManager()->allKnownGroups());
}
@@ -1071,7 +1071,7 @@ void MainWidget::selectAvatarFromAccount(const QString &accountUID)
Tp::Avatar avatar = qobject_cast<AccountsModelItem*>(m_model->accountItemForId(accountUID))->data(AccountsModel::AvatarRole).value<Tp::Avatar>();
- foreach (const Tp::AccountPtr account, m_accountManager->allAccounts()) {
+ foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
//don't set the avatar for the account from where it was taken
if (account->uniqueIdentifier() == accountUID) {
continue;
@@ -1150,7 +1150,7 @@ void MainWidget::onAvatarFetched(KJob *job)
Q_ASSERT(fetchJob);
- foreach (const Tp::AccountPtr account, m_accountManager->allAccounts()) {
+ foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
Tp::PendingOperation *op = account->setAvatar(fetchJob->avatar());
//connect for eventual error displaying
@@ -1289,4 +1289,82 @@ void MainWidget::onSwitchToCompactView()
guiConfigGroup.config()->sync();
}
+void MainWidget::closeEvent(QCloseEvent* e)
+{
+ KSharedConfigPtr config = KGlobal::config();
+ KConfigGroup generalConfigGroup(config, "General");
+
+ bool checkForPlasmoid = generalConfigGroup.readEntry("check_for_plasmoid", true);
+
+ if (checkForPlasmoid) {
+
+ if (!isPlasmoidPresent()) {
+ KDialog *noPlasmoidDialog = new KDialog(this);
+
+ QWidget *dialogMainWidget = new QWidget(noPlasmoidDialog);
+
+ QLabel *text = new QLabel(i18n("You don't have any other presence controls active (a Presence plasmoid for example).\n\n"
+ "Do you want to stay online or would you rather go offline?\n\n"),
+ dialogMainWidget);
+ QCheckBox *dontAskCheckbox = new QCheckBox(i18n("Remember my preference"), dialogMainWidget);
+
+ QLabel *icon = new QLabel();
+ icon->setPixmap(KIconLoader::global()->loadIcon("dialog-information", KIconLoader::Dialog, 48));
+
+ QHBoxLayout *mainLayout = new QHBoxLayout(dialogMainWidget);
+ mainLayout->addWidget(icon);
+
+ QVBoxLayout *innerLayout = new QVBoxLayout(dialogMainWidget);
+ innerLayout->addWidget(text);
+ innerLayout->addWidget(dontAskCheckbox);
+
+ mainLayout->addLayout(innerLayout);
+
+ noPlasmoidDialog->setCaption(i18n("No other presence controls found"));
+ noPlasmoidDialog->setButtons(KDialog::Yes | KDialog::No);
+ noPlasmoidDialog->setMainWidget(dialogMainWidget);
+ noPlasmoidDialog->setButtonText(KDialog::Yes, i18n("Stay online"));
+ noPlasmoidDialog->setButtonText(KDialog::No, i18n("Go offline"));
+
+ if (noPlasmoidDialog->exec() == KDialog::No) {
+ generalConfigGroup.writeEntry("go_offline_when_closing", true);
+ goOffline();
+ }
+
+ if (dontAskCheckbox->isChecked()) {
+ generalConfigGroup.writeEntry("check_for_plasmoid", false);
+ }
+
+ generalConfigGroup.config()->sync();
+ }
+ } else {
+ bool shouldGoOffline = generalConfigGroup.readEntry("go_offline_when_closing", false);
+ if (shouldGoOffline) {
+ goOffline();
+ }
+ }
+
+ KMainWindow::closeEvent(e);
+}
+
+bool MainWidget::isPlasmoidPresent()
+{
+ QDBusInterface plasmoidOnDbus("org.kde.Telepathy.PresenceEngineActive", "/PresenceEngineActive");
+
+ if (plasmoidOnDbus.isValid()) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void MainWidget::goOffline()
+{
+ foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
+ if (account->isEnabled() && account->isValid()) {
+ account->setRequestedPresence(Tp::Presence::offline());
+ }
+ }
+}
+
#include "main-widget.moc"
diff --git a/main-widget.h b/main-widget.h
index 313f74f..dbe2f17 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -51,6 +51,8 @@ public:
MainWidget(QWidget *parent = 0);
~MainWidget();
+ bool isPlasmoidPresent();
+
enum SystemMessageType {
/*
* this will show a system message to the user
@@ -95,6 +97,7 @@ public Q_SLOTS:
void onCustomContextMenuRequested(const QPoint &point);
void onGroupContacts(bool enabled);
void onJoinChatRoomRequested(); /** join chat room action is triggered */
+ void goOffline();
private Q_SLOTS:
void slotAddContactToGroupTriggered();
@@ -121,6 +124,7 @@ Q_SIGNALS:
private:
/** handle connection errors for given account. This method provides visual notification */
void handleConnectionError(const Tp::AccountPtr &account);
+ void closeEvent(QCloseEvent *e);
AccountsModel *m_model;
GroupsModel *m_groupsModel;