[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:07:23 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=54600f7

The following commit has been merged in the master branch:
commit 54600f7bfef6183c6e7106a05b943c9d502810e1
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Mon Sep 12 18:39:29 2011 +0200

    First refactor of MainWidget class. So far, only avatar handling code was moved out to a separate class and bunch of slots were moved and/or renamed.
    
    Reviewed-by: David Edmundson
    REVIEW: 102584
    CCBUG: 279107
---
 CMakeLists.txt    |   2 +-
 avatar-button.cpp | 228 ++++++++++++++++++++++++++++++++++++++++++++
 avatar-button.h   |  62 ++++++++++++
 main-widget.cpp   | 276 ++++++++++--------------------------------------------
 main-widget.h     |  69 +++++++-------
 main-widget.ui    |   7 +-
 6 files changed, 382 insertions(+), 262 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b01272f..c2fa1b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,7 @@ include_directories (${KDE4_INCLUDES}
                      ${TELEPATHY_QT4_INCLUDE_DIR}
 )
 
-set (contactlist_SRCS
+set (contactlist_SRCS avatar-button.cpp
      abstract-contact-delegate.cpp
      contact-list-application.cpp
      contact-view-hover-button.cpp
diff --git a/avatar-button.cpp b/avatar-button.cpp
new file mode 100644
index 0000000..0c9421f
--- /dev/null
+++ b/avatar-button.cpp
@@ -0,0 +1,228 @@
+/*
+ * Button representing user's Avatar
+ *
+ * Copyright (C) 2011  Martin Klapetek <martin.klapetek at gmail.com>
+ *
+ * This 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "avatar-button.h"
+
+#include <QWidgetAction>
+
+#include <KDebug>
+#include <KFileDialog>
+#include <KMessageBox>
+#include <KMenu>
+#include <KLocalizedString>
+#include <KSharedConfig>
+
+#include "models/accounts-model.h"
+#include "fetch-avatar-job.h"
+
+AvatarButton::AvatarButton(QWidget *parent)
+    : QToolButton(parent),
+      //m_accountManager(0),
+      m_accountsModel(0)
+{
+//     m_accountManager = am;
+//     m_accountsModel = model;
+    m_avatarButtonMenu = new KMenu(this);
+
+    QToolButton *loadFromFileButton = new QToolButton(this);
+    loadFromFileButton->setIcon(KIcon("document-open-folder"));
+    loadFromFileButton->setIconSize(QSize(48, 48));
+    loadFromFileButton->setText(i18n("Load from file..."));
+    loadFromFileButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+
+    QWidgetAction *loadFromFileAction = new QWidgetAction(this);
+    loadFromFileAction->setDefaultWidget(loadFromFileButton);
+
+    connect(loadFromFileButton, SIGNAL(clicked(bool)),
+            this, SLOT(loadAvatarFromFile()));
+
+    connect(loadFromFileAction, SIGNAL(triggered(bool)),
+            this, SLOT(loadAvatarFromFile()));
+
+    m_avatarButtonMenu->addAction(loadFromFileAction);
+
+    setMenu(m_avatarButtonMenu);
+}
+
+AvatarButton::~AvatarButton()
+{
+
+}
+
+void AvatarButton::initialize(AccountsModel* model, const Tp::AccountManagerPtr& manager)
+{
+    m_accountsModel = model;
+    m_accountManager = manager;
+}
+
+void AvatarButton::loadAvatar(const Tp::AccountPtr &account)
+{
+    if (!account->avatar().avatarData.isEmpty()) {
+        QIcon icon;
+        Tp::Avatar avatar = account->avatar();
+        icon.addPixmap(QPixmap::fromImage(QImage::fromData(avatar.avatarData)).scaled(48, 48));
+
+        QToolButton *avatarMenuItem = new QToolButton(this);
+        avatarMenuItem->setIcon(icon);
+        avatarMenuItem->setIconSize(QSize(48, 48));
+        avatarMenuItem->setText(i18nc("String in menu saying Use avatar from account X",
+                                    "Use from %1", account->displayName()));
+        avatarMenuItem->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+
+        QWidgetAction *avatarAction = new QWidgetAction(m_avatarButtonMenu);
+        avatarAction->setDefaultWidget(avatarMenuItem);
+        avatarAction->setData(account->uniqueIdentifier());
+
+        connect(this, SIGNAL(clicked(bool)),
+                this, SLOT(selectAvatarFromAccount()));
+
+        connect(avatarAction, SIGNAL(triggered(bool)),
+                this, SLOT(selectAvatarFromAccount()));
+
+        m_avatarButtonMenu->addAction(avatarAction);
+    }
+}
+
+void AvatarButton::selectAvatarFromAccount()
+{
+    selectAvatarFromAccount(qobject_cast<QWidgetAction*>(sender())->data().toString());
+}
+
+void AvatarButton::selectAvatarFromAccount(const QString &accountUID)
+{
+    if (accountUID.isEmpty()) {
+        kDebug() << "Supplied accountUID is empty, aborting...";
+        return;
+    }
+
+    if (m_accountsModel->accountItemForId(accountUID) == 0) {
+        kDebug() << "Chosen account ID does not exist, aborting..";
+
+        //no point of keeping the config if the previously set account ID does not exist
+        KSharedConfigPtr config = KGlobal::config();
+        KConfigGroup avatarGroup(config, "Avatar");
+        avatarGroup.deleteGroup();
+        avatarGroup.config()->sync();
+
+        return;
+    }
+
+    Tp::Avatar avatar = qobject_cast<AccountsModelItem*>(m_accountsModel->accountItemForId(accountUID))->data(AccountsModel::AvatarRole).value<Tp::Avatar>();
+
+    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;
+        }
+
+        account->setAvatar(avatar);
+    }
+
+    //add the selected avatar as the icon of avatar button
+    QIcon icon;
+    icon.addPixmap(QPixmap::fromImage(QImage::fromData(avatar.avatarData)).scaled(48, 48));
+    setIcon(icon);
+
+    m_avatarButtonMenu->close();
+
+    //save the selected account into config
+    KSharedConfigPtr config = KGlobal::config();
+    KConfigGroup avatarGroup(config, "Avatar");
+    avatarGroup.writeEntry("method", "account");
+    avatarGroup.writeEntry("source", accountUID);
+    avatarGroup.config()->sync();
+}
+
+void AvatarButton::loadAvatarFromFile()
+{
+    if (m_accountManager->allAccounts().isEmpty()) {
+        int returnCode = KMessageBox::warningYesNo(this,
+                                                   i18nc("Dialog text", "You have no accounts set. Would you like to set one now?"),
+                                                   i18nc("Dialog caption", "No accounts set"));
+
+        if (returnCode == KMessageBox::Yes) {
+            emit openKCMSettings();
+            loadAvatarFromFile();
+        } else {
+            return;
+        }
+    } else {
+        KUrl fileUrl = KFileDialog::getImageOpenUrl(KUrl(), this,
+                                                    i18n("Please choose your avatar"));
+
+        if (!fileUrl.isEmpty()) {
+            FetchAvatarJob *job = new FetchAvatarJob(fileUrl, this);
+
+            connect(job, SIGNAL(result(KJob*)),
+                    this, SLOT(onAvatarFetched(KJob*)));
+
+            job->start();
+        } else {
+            return;
+        }
+    }
+}
+
+void AvatarButton::onAvatarFetched(KJob *job)
+{
+    if (job->error()) {
+        KMessageBox::error(this, job->errorString());
+        return;
+    }
+
+    //this should never be true, but better one "if" than a crash
+    if (m_accountManager->allAccounts().isEmpty()) {
+        int returnCode = KMessageBox::warningYesNo(this,
+                                                   i18nc("Dialog text", "You have no accounts set. Would you like to set one now?"),
+                                                   i18nc("Dialog caption", "No accounts set"));
+
+        if (returnCode == KMessageBox::Yes) {
+            emit openKCMSettings();
+        } else {
+            return;
+        }
+    } else {
+
+        FetchAvatarJob *fetchJob = qobject_cast< FetchAvatarJob* >(job);
+
+        Q_ASSERT(fetchJob);
+
+        foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
+            Tp::PendingOperation *op = account->setAvatar(fetchJob->avatar());
+
+            //connect for eventual error displaying
+            connect(op, SIGNAL(finished(Tp::PendingOperation*)),
+                    this, SIGNAL(operationFinished(Tp::PendingOperation*)));
+        }
+
+        //add the selected avatar to the avatar button
+        QIcon icon;
+        icon.addPixmap(QPixmap::fromImage(QImage::fromData(fetchJob->avatar().avatarData)).scaled(48, 48));
+        setIcon(icon);
+
+        //since all the accounts will have the same avatar,
+        //we take simply the first in AM and use this in config
+        KSharedConfigPtr config = KGlobal::config();
+        KConfigGroup avatarGroup(config, "Avatar");
+        avatarGroup.writeEntry("method", "account");
+        avatarGroup.writeEntry("source", m_accountManager->allAccounts().first()->uniqueIdentifier());
+        avatarGroup.config()->sync();
+    }
+}
\ No newline at end of file
diff --git a/avatar-button.h b/avatar-button.h
new file mode 100644
index 0000000..a147a63
--- /dev/null
+++ b/avatar-button.h
@@ -0,0 +1,62 @@
+/*
+ * Button representing user's Avatar
+ *
+ * Copyright (C) 2011  Martin Klapetek <martin.klapetek at gmail.com>
+ *
+ * This 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef AVATAR_BUTTON_H
+#define AVATAR_BUTTON_H
+
+#include <QtGui/QToolButton>
+#include <TelepathyQt4/Account>
+
+namespace Tp {
+class PendingOperation;
+}
+
+class AccountsModel;
+class KJob;
+class KMenu;
+
+class AvatarButton : public QToolButton
+{
+    Q_OBJECT
+
+public:
+    AvatarButton(QWidget* parent = 0);
+    ~AvatarButton();
+    void initialize(AccountsModel *model, const Tp::AccountManagerPtr &manager);
+
+Q_SIGNALS:
+    void openKCMSettings();
+    void operationFinished(Tp::PendingOperation*);
+
+public Q_SLOTS:
+    void loadAvatar(const Tp::AccountPtr &account);
+    void selectAvatarFromAccount(const QString &accountUID);
+
+private Q_SLOTS:
+    void selectAvatarFromAccount();
+    void loadAvatarFromFile();
+
+    void onAvatarFetched(KJob*);
+
+private:
+    KMenu                 *m_avatarButtonMenu;
+    Tp::AccountManagerPtr  m_accountManager;
+    AccountsModel         *m_accountsModel;
+};
diff --git a/main-widget.cpp b/main-widget.cpp
index 214c8e7..a4f27a8 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -67,7 +67,6 @@
 #include "dialogs/remove-contact-dialog.h"
 #include "dialogs/contact-info.h"
 
-
 #include "models/groups-model.h"
 #include "models/contact-model-item.h"
 #include "models/groups-model-item.h"
@@ -104,28 +103,7 @@ MainWidget::MainWidget(QWidget *parent)
         user.loginName() : user.property(KUser::FullName).toString()
     );
 
-    m_userAccountIconButton->setPopupMode(QToolButton::InstantPopup);
-
-    m_avatarButtonMenu = new KMenu(m_userAccountIconButton);
-
-    QToolButton *loadFromFileButton = new QToolButton(this);
-    loadFromFileButton->setIcon(KIcon("document-open-folder"));
-    loadFromFileButton->setIconSize(QSize(48, 48));
-    loadFromFileButton->setText(i18n("Load from file..."));
-    loadFromFileButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
-
-    QWidgetAction *loadFromFileAction = new QWidgetAction(this);
-    loadFromFileAction->setDefaultWidget(loadFromFileButton);
-
-    connect(loadFromFileButton, SIGNAL(clicked(bool)),
-            loadFromFileAction, SIGNAL(triggered(bool)));
-
-    connect(loadFromFileAction, SIGNAL(triggered(bool)),
-            this, SLOT(loadAvatarFromFile()));
-
-    m_avatarButtonMenu->addAction(loadFromFileAction);
-
-    m_userAccountIconButton->setMenu(m_avatarButtonMenu);
+    m_avatarButton->setPopupMode(QToolButton::InstantPopup);
 
     m_toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
 
@@ -266,7 +244,7 @@ MainWidget::MainWidget(QWidget *parent)
             this, SLOT(onContactListClicked(QModelIndex)));
 
     connect(m_contactsListView, SIGNAL(doubleClicked(QModelIndex)),
-            this, SLOT(onContactListDoubleClick(QModelIndex)));
+            this, SLOT(onContactListDoubleClicked(QModelIndex)));
 
     connect(m_delegate, SIGNAL(repaintItem(QModelIndex)),
             m_contactsListView->viewport(), SLOT(repaint())); //update(QModelIndex)
@@ -275,7 +253,7 @@ MainWidget::MainWidget(QWidget *parent)
             this, SLOT(onAddContactRequest()));
 
     connect(m_groupContactsAction, SIGNAL(triggered(bool)),
-            this, SLOT(onGroupContacts(bool)));
+            this, SLOT(groupContacts(bool)));
 
     connect(m_searchContactAction, SIGNAL(triggered(bool)),
             this, SLOT(toggleSearchWidget(bool)));
@@ -283,6 +261,9 @@ MainWidget::MainWidget(QWidget *parent)
     connect(m_presenceMessageEdit, SIGNAL(returnPressed(QString)),
             this, SLOT(setCustomPresenceMessage(QString)));
 
+    connect(m_avatarButton, SIGNAL(operationFinished(Tp::PendingOperation*)),
+            this, SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
+
     if (guiConfigGroup.readEntry("pin_filterbar", true)) {
         toggleSearchWidget(true);
         m_searchContactAction->setChecked(true);
@@ -349,6 +330,8 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
 
     m_accountButtonsLayout->insertStretch(-1);
 
+    m_avatarButton->initialize(m_model, m_accountManager);
+
     QList<Tp::AccountPtr> accounts = m_accountManager->allAccounts();
 
     if(accounts.count() == 0) {
@@ -375,7 +358,7 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
     KConfigGroup guiConfigGroup(config, "GUI");
 
     bool useGroups = guiConfigGroup.readEntry("use_groups", true);
-    onGroupContacts(useGroups);
+    groupContacts(useGroups);
     m_groupContactsAction->setChecked(useGroups);
 
     bool showOffline = guiConfigGroup.readEntry("show_offline", false);
@@ -439,14 +422,14 @@ void MainWidget::onNewAccountAdded(const Tp::AccountPtr& account)
 
     if(account->isEnabled()) {
         bt->show();
-        loadAvatar(account);
+        m_avatarButton->loadAvatar(account);
     }
 
     KSharedConfigPtr config = KGlobal::config();
     KConfigGroup avatarGroup(config, "Avatar");
     if (avatarGroup.readEntry("method", QString()) == QLatin1String("account")) {
         //this also updates the avatar if it was changed somewhere else
-        selectAvatarFromAccount(avatarGroup.readEntry("source", QString()));
+        m_avatarButton->selectAvatarFromAccount(avatarGroup.readEntry("source", QString()));
     }
 }
 
@@ -526,7 +509,7 @@ void MainWidget::onContactListClicked(const QModelIndex& index)
     }
 }
 
-void MainWidget::onContactListDoubleClick(const QModelIndex& index)
+void MainWidget::onContactListDoubleClicked(const QModelIndex& index)
 {
     if (!index.isValid()) {
         return;
@@ -551,7 +534,7 @@ void MainWidget::startTextChannel(ContactModelItem *contactItem)
                                                                         QDateTime::currentDateTime(),
                                                                         PREFERRED_TEXTCHAT_HANDLER);
     connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)),
-            this, SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            this, SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 }
 
 void MainWidget::startAudioChannel(ContactModelItem *contactItem)
@@ -567,7 +550,7 @@ void MainWidget::startAudioChannel(ContactModelItem *contactItem)
                                                                         QDateTime::currentDateTime(),
                                                                         PREFERRED_AUDIO_VIDEO_HANDLER);
     connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)),
-            this, SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            this, SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 }
 
 void MainWidget::startVideoChannel(ContactModelItem *contactItem)
@@ -583,7 +566,7 @@ void MainWidget::startVideoChannel(ContactModelItem *contactItem)
                                                                         QDateTime::currentDateTime(),
                                                                         PREFERRED_AUDIO_VIDEO_HANDLER);
     connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)),
-            this, SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            this, SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 }
 
 
@@ -618,7 +601,7 @@ void MainWidget::startFileTransferChannel(ContactModelItem *contactItem)
                                                                             fileTransferProperties,
                                                                             QDateTime::currentDateTime(),
                                                                             PREFERRED_FILETRANSFER_HANDLER);
-    connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)), SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+    connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 }
 
 void MainWidget::showMessageToUser(const QString& text, const MainWidget::SystemMessageType type)
@@ -783,7 +766,7 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
     action->setIcon(KIcon("mail-message-new"));
     action->setDisabled(true);
     connect(action, SIGNAL(triggered(bool)),
-            SLOT(slotStartTextChat()));
+            SLOT(onStartTextChatTriggered()));
 
     if (index.data(AccountsModel::TextChatCapabilityRole).toBool()) {
         action->setEnabled(true);
@@ -799,7 +782,7 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
     action->setIcon(KIcon("voicecall"));
     action->setDisabled(true);
     connect(action, SIGNAL(triggered(bool)),
-            SLOT(slotStartAudioChat()));
+            SLOT(onStartAudioChatTriggered()));
 
     if (index.data(AccountsModel::AudioCallCapabilityRole).toBool()) {
         action->setEnabled(true);
@@ -809,7 +792,7 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
     action->setIcon(KIcon("webcamsend"));
     action->setDisabled(true);
     connect(action, SIGNAL(triggered(bool)),
-            SLOT(slotStartVideoChat()));
+            SLOT(onStartVideoChatTriggered()));
 
     if (index.data(AccountsModel::VideoCallCapabilityRole).toBool()) {
         action->setEnabled(true);
@@ -819,7 +802,7 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
     action->setIcon(KIcon("mail-attachment"));
     action->setDisabled(true);
     connect(action, SIGNAL(triggered(bool)),
-            SLOT(slotStartFileTransfer()));
+            SLOT(onStartFileTransferTriggered()));
 
     if (index.data(AccountsModel::FileTransferCapabilityRole).toBool()) {
         action->setEnabled(true);
@@ -829,7 +812,7 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
 
     // remove contact action
     QAction *removeAction = menu->addAction(KIcon("list-remove-user"), i18n("Remove Contact"));
-    connect(removeAction, SIGNAL(triggered(bool)), this, SLOT(slotDeleteContact()));
+    connect(removeAction, SIGNAL(triggered(bool)), this, SLOT(onDeleteContactTriggered()));
 
     if (accountConnection->actualFeatures().contains(Tp::Connection::FeatureRosterGroups)) {
         QMenu* groupAddMenu = menu->addMenu(i18n("Move to Group"));
@@ -851,13 +834,13 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
         }
 
         connect(groupAddMenu->addAction(i18n("Create New Group...")), SIGNAL(triggered(bool)),
-                this, SLOT(onCreateNewGroup()));
+                this, SLOT(onCreateNewGroupTriggered()));
 
         groupAddMenu->addSeparator();
 
         foreach (const QString &group, groupList) {
             connect(groupAddMenu->addAction(group), SIGNAL(triggered(bool)),
-                    SLOT(slotAddContactToGroupTriggered()));
+                    SLOT(onAddContactToGroupTriggered()));
         }
     } else {
         kDebug() << "Unable to support Groups";
@@ -880,7 +863,7 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
 
     action = menu->addAction(i18n("Show Info..."));
     action->setIcon(KIcon(""));
-    connect(action, SIGNAL(triggered()), SLOT(slotShowInfo()));
+    connect(action, SIGNAL(triggered()), SLOT(onShowInfoTriggered()));
 
     return menu;
 }
@@ -913,7 +896,7 @@ KMenu* MainWidget::groupContextMenu(const QModelIndex &index)
     return menu;
 }
 
-void MainWidget::slotAddContactToGroupTriggered()
+void MainWidget::onAddContactToGroupTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     ContactModelItem* contactItem = index.data(AccountsModel::ItemRole).value<ContactModelItem*>();
@@ -933,17 +916,17 @@ void MainWidget::slotAddContactToGroupTriggered()
 
     if (operation) {
         connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-                SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+                SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 
         foreach (const QString &group, currentGroups) {
             Tp::PendingOperation* operation = contact->removeFromGroup(group);
             connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-                    SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+                    SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
         }
     }
 }
 
-void MainWidget::onCreateNewGroup()
+void MainWidget::onCreateNewGroupTriggered()
 {
     QString newGroupName = KInputDialog::getText(i18n("New Group Name"), i18n("Please enter the new group name"));
 
@@ -955,10 +938,10 @@ void MainWidget::onCreateNewGroup()
     Tp::PendingOperation *operation = contact->addToGroup(newGroupName);
 
     connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 }
 
-void MainWidget::onRenameGroup()
+void MainWidget::onRenameGroupTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
 
@@ -975,15 +958,15 @@ void MainWidget::onRenameGroup()
 
         Tp::PendingOperation *operation = contact->addToGroup(newGroupName);
         connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-                SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+                SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 
         operation = contact->removeFromGroup(groupItem->groupName());
         connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-                SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+                SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
     }
 }
 
-void MainWidget::onDeleteGroup()
+void MainWidget::onDeleteGroupTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
 
@@ -1001,21 +984,21 @@ void MainWidget::onDeleteGroup()
 
             Tp::PendingOperation *operation = contact->removeFromGroup(groupItem->groupName());
             connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-                    SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+                    SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
         }
 
         foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
             if (account->connection()) {
                 Tp::PendingOperation *operation = account->connection()->contactManager()->removeGroup(groupItem->groupName());
                 connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-                        SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+                        SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
             }
         }
     }
 }
 
 
-void MainWidget::slotBlockContactTriggered()
+void MainWidget::onBlockContactTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     ContactModelItem* contactItem = index.data(AccountsModel::ItemRole).value<ContactModelItem*>();
@@ -1025,10 +1008,10 @@ void MainWidget::slotBlockContactTriggered()
 
     Tp::PendingOperation *operation = contact->block(true);
     connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 }
 
-void MainWidget::slotDeleteContact()
+void MainWidget::onDeleteContactTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     ContactModelItem* contactItem = index.data(AccountsModel::ItemRole).value<ContactModelItem*>();
@@ -1045,19 +1028,19 @@ void MainWidget::slotDeleteContact()
     if (removeDialog.data()->exec() == QDialog::Accepted) {
         // remove from contact list
         Tp::PendingOperation *deleteOp = contact->manager()->removeContacts(contactList);
-        connect(deleteOp, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+        connect(deleteOp, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 
         if (removeDialog.data()->blockContact()) {
             // block contact
             Tp::PendingOperation *blockOp = contact->manager()->blockContacts(contactList);
-            connect(blockOp, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            connect(blockOp, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
         }
     }
 
     delete removeDialog.data();
 }
 
-void MainWidget::slotGenericOperationFinished(Tp::PendingOperation* operation)
+void MainWidget::onGenericOperationFinished(Tp::PendingOperation* operation)
 {
     if (operation->isError()) {
         QString errorMsg(operation->errorName() + ": " + operation->errorMessage());
@@ -1065,7 +1048,7 @@ void MainWidget::slotGenericOperationFinished(Tp::PendingOperation* operation)
     }
 }
 
-void MainWidget::slotShowInfo()
+void MainWidget::onShowInfoTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     if (!index.isValid()) {
@@ -1085,7 +1068,7 @@ void MainWidget::showInfo(ContactModelItem *contactItem)
     contactInfoDialog.exec();
 }
 
-void MainWidget::slotStartTextChat()
+void MainWidget::onStartTextChatTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     if (!index.isValid()) {
@@ -1099,7 +1082,7 @@ void MainWidget::slotStartTextChat()
     }
 }
 
-void MainWidget::slotStartAudioChat()
+void MainWidget::onStartAudioChatTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     if (!index.isValid()) {
@@ -1113,7 +1096,7 @@ void MainWidget::slotStartAudioChat()
     }
 }
 
-void MainWidget::slotStartVideoChat()
+void MainWidget::onStartVideoChatTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     if (!index.isValid()) {
@@ -1126,7 +1109,7 @@ void MainWidget::slotStartVideoChat()
     }
 }
 
-void MainWidget::slotStartFileTransfer()
+void MainWidget::onStartFileTransferTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     if (!index.isValid()) {
@@ -1140,7 +1123,7 @@ void MainWidget::slotStartFileTransfer()
     }
 }
 
-void MainWidget::slotUnblockContactTriggered()
+void MainWidget::onUnblockContactTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
     ContactModelItem* item = index.data(AccountsModel::ItemRole).value<ContactModelItem*>();
@@ -1150,7 +1133,7 @@ void MainWidget::slotUnblockContactTriggered()
 
     Tp::PendingOperation *operation = contact->block(false);
     connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
 }
 
 
@@ -1174,163 +1157,6 @@ void MainWidget::showSettingsKCM()
     dialog->exec();
 }
 
-void MainWidget::loadAvatar(const Tp::AccountPtr &account)
-{
-    if (!account->avatar().avatarData.isEmpty()) {
-        QIcon icon;
-        Tp::Avatar avatar = account->avatar();
-        icon.addPixmap(QPixmap::fromImage(QImage::fromData(avatar.avatarData)).scaled(48, 48));
-
-        QToolButton *avatarButton = new QToolButton(this);
-        avatarButton->setIcon(icon);
-        avatarButton->setIconSize(QSize(48, 48));
-        avatarButton->setText(i18nc("String in menu saying Use avatar from account X",
-                                    "Use from %1", account->displayName()));
-        avatarButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
-
-        QWidgetAction *avatarAction = new QWidgetAction(m_avatarButtonMenu);
-        avatarAction->setDefaultWidget(avatarButton);
-        avatarAction->setData(account->uniqueIdentifier());
-
-        connect(avatarButton, SIGNAL(clicked(bool)),
-                avatarAction, SIGNAL(triggered(bool)));
-
-        connect(avatarAction, SIGNAL(triggered(bool)),
-                this, SLOT(selectAvatarFromAccount()));
-
-
-        m_avatarButtonMenu->addAction(avatarAction);
-    }
-}
-
-void MainWidget::selectAvatarFromAccount()
-{
-    selectAvatarFromAccount(qobject_cast<QWidgetAction*>(sender())->data().toString());
-}
-
-void MainWidget::selectAvatarFromAccount(const QString &accountUID)
-{
-    if (accountUID.isEmpty()) {
-        kDebug() << "Supplied accountUID is empty, aborting...";
-        return;
-    }
-
-    if (m_model->accountItemForId(accountUID) == 0) {
-        kDebug() << "Chosen account ID does not exist, aborting..";
-
-        //no point of keeping the config if the previously set account ID does not exist
-        KSharedConfigPtr config = KGlobal::config();
-        KConfigGroup avatarGroup(config, "Avatar");
-        avatarGroup.deleteGroup();
-        avatarGroup.config()->sync();
-
-        return;
-    }
-
-    Tp::Avatar avatar = qobject_cast<AccountsModelItem*>(m_model->accountItemForId(accountUID))->data(AccountsModel::AvatarRole).value<Tp::Avatar>();
-
-    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;
-        }
-
-        account->setAvatar(avatar);
-    }
-
-    //add the selected avatar as the icon of avatar button
-    QIcon icon;
-    icon.addPixmap(QPixmap::fromImage(QImage::fromData(avatar.avatarData)).scaled(48, 48));
-    m_userAccountIconButton->setIcon(icon);
-
-    m_avatarButtonMenu->close();
-
-    //save the selected account into config
-    KSharedConfigPtr config = KGlobal::config();
-    KConfigGroup avatarGroup(config, "Avatar");
-    avatarGroup.writeEntry("method", "account");
-    avatarGroup.writeEntry("source", accountUID);
-    avatarGroup.config()->sync();
-
-}
-
-void MainWidget::loadAvatarFromFile()
-{
-    if (m_accountManager->allAccounts().isEmpty()) {
-        int returnCode = KMessageBox::warningYesNo(this,
-                                           i18nc("Dialog text", "You have no accounts set. Would you like to set one now?"),
-                                           i18nc("Dialog caption", "No accounts set"));
-
-        if (returnCode == KMessageBox::Yes) {
-            showSettingsKCM();
-            loadAvatarFromFile();
-        } else {
-            return;
-        }
-    } else {
-        KUrl fileUrl = KFileDialog::getImageOpenUrl(KUrl(), this,
-                                     i18n("Please choose your avatar"));
-
-        if (!fileUrl.isEmpty()) {
-            FetchAvatarJob *job = new FetchAvatarJob(fileUrl, this);
-
-            connect(job, SIGNAL(result(KJob*)),
-                    this, SLOT(onAvatarFetched(KJob*)));
-
-            job->start();
-        } else {
-            return;
-        }
-    }
-}
-
-void MainWidget::onAvatarFetched(KJob *job)
-{
-    if (job->error()) {
-        KMessageBox::error(this, job->errorString());
-        return;
-    }
-
-    //this should never be true, but better one "if" than a crash
-    if (m_accountManager->allAccounts().isEmpty()) {
-        int returnCode = KMessageBox::warningYesNo(this,
-                                                   i18nc("Dialog text", "You have no accounts set. Would you like to set one now?"),
-                                                   i18nc("Dialog caption", "No accounts set"));
-
-        if (returnCode == KMessageBox::Yes) {
-            showSettingsKCM();
-        } else {
-            return;
-        }
-    } else {
-
-        FetchAvatarJob *fetchJob = qobject_cast< FetchAvatarJob* >(job);
-
-        Q_ASSERT(fetchJob);
-
-        foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
-            Tp::PendingOperation *op = account->setAvatar(fetchJob->avatar());
-
-            //connect for eventual error displaying
-            connect(op, SIGNAL(finished(Tp::PendingOperation*)),
-                    this, SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
-        }
-
-        //add the selected avatar to the avatar button
-        QIcon icon;
-        icon.addPixmap(QPixmap::fromImage(QImage::fromData(fetchJob->avatar().avatarData)).scaled(48, 48));
-        m_userAccountIconButton->setIcon(icon);
-
-        //since all the accounts will have the same avatar,
-        //we take simply the first in AM and use this in config
-        KSharedConfigPtr config = KGlobal::config();
-        KConfigGroup avatarGroup(config, "Avatar");
-        avatarGroup.writeEntry("method", "account");
-        avatarGroup.writeEntry("source", m_accountManager->allAccounts().first()->uniqueIdentifier());
-        avatarGroup.config()->sync();
-    }
-}
-
 void MainWidget::onAccountsPresenceStatusFiltered()
 {
     kDebug() << "Watcher is here";
@@ -1366,7 +1192,7 @@ void MainWidget::onPresencePublicationRequested(const Tp::Contacts& contacts)
 
         if (op) {
             connect(op, SIGNAL(finished(Tp::PendingOperation*)),
-                    SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+                    SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
         }
     }
 }
@@ -1392,7 +1218,7 @@ void MainWidget::handleConnectionError(const Tp::AccountPtr& account)
     }
 }
 
-void MainWidget::onGroupContacts(bool enabled)
+void MainWidget::groupContacts(bool enabled)
 {
     if (enabled) {
         m_modelFilter->setSourceModel(m_groupsModel);
@@ -1414,7 +1240,7 @@ void MainWidget::onJoinChatRoomRequested()
             Tp::PendingChannelRequest *channelRequest = account->ensureTextChatroom(dialog.data()->selectedChatRoom(),
                                                                                     QDateTime::currentDateTime(),
                                                                                     PREFERRED_TEXTCHAT_HANDLER);
-            connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)), SLOT(slotGenericOperationFinished(Tp::PendingOperation*)));
+            connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
         }
     }
 
diff --git a/main-widget.h b/main-widget.h
index bc3d1f8..34a41d9 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -1,5 +1,5 @@
 /*
- * This file is part of telepathy-contactslist-prototype
+ * This file is part of telepathy-contact-list
  *
  * Copyright (C) 2009-2010 Collabora Ltd. <info at collabora.co.uk>
  *   @Author George Goldberg <george.goldberg at collabora.co.uk>
@@ -53,6 +53,7 @@ public:
 
     bool isPresencePlasmoidPresent() const;
     bool isAnyAccountOnline() const;
+    void addOverlayButtons();
 
     enum SystemMessageType {
         /*
@@ -71,58 +72,57 @@ public:
     };
 
 public Q_SLOTS:
-    void onAccountManagerReady(Tp::PendingOperation *op);
-
-    void onContactListClicked(const QModelIndex &index);
-    void onContactListDoubleClick(const QModelIndex &index);
-    void onConnectionChanged(const Tp::ConnectionPtr &connection);
-    void onAccountConnectionStatusChanged(Tp::ConnectionStatus status);
-    void showMessageToUser(const QString &text, const SystemMessageType type);
-    void addOverlayButtons();
+    void onAddContactRequest();
+    void onAddContactRequestFoundContacts(Tp::PendingOperation *operation);
     void onNewAccountAdded(const Tp::AccountPtr &account);
     void onAccountStateChanged(bool enabled);
     void onAccountRemoved();
+
     void toggleSearchWidget(bool show);
     void setCustomPresenceMessage(const QString &message);
     void showSettingsKCM();
-    void onAddContactRequest();
-    void onAddContactRequestFoundContacts(Tp::PendingOperation *operation);
-    void loadAvatar(const Tp::AccountPtr &account);
-    void selectAvatarFromAccount(const QString &accountUID);
-    void selectAvatarFromAccount();
-    void loadAvatarFromFile();
+    void showMessageToUser(const QString &text, const SystemMessageType type);
     void showInfo(ContactModelItem *contactItem);
     void startTextChannel(ContactModelItem *contactItem);
     void startFileTransferChannel(ContactModelItem *contactItem);
     void startAudioChannel(ContactModelItem *contactItem);
     void startVideoChannel(ContactModelItem *contactItem);
-    void onCustomContextMenuRequested(const QPoint &point);
-    void onGroupContacts(bool enabled);
-    void onJoinChatRoomRequested();         /** join chat room action is triggered */
+
     void goOffline();
 
 private Q_SLOTS:
-    void slotAddContactToGroupTriggered();
-    void slotBlockContactTriggered();
-    void slotDeleteContact();
-    void slotGenericOperationFinished(Tp::PendingOperation *operation); /** called when a Tp::PendingOperation finishes. Used to check for errors */
-    void slotShowInfo();
-    void slotStartTextChat();
-    void slotStartAudioChat();
-    void slotStartVideoChat();
-    void slotStartFileTransfer();
-    void slotUnblockContactTriggered();
-    void onAvatarFetched(KJob*);
+    void onAddContactToGroupTriggered();
+    void onBlockContactTriggered();
+    void onStartTextChatTriggered();
+    void onStartAudioChatTriggered();
+    void onStartVideoChatTriggered();
+    void onStartFileTransferTriggered();
+    void onUnblockContactTriggered();
+    void onCreateNewGroupTriggered();
+    void onRenameGroupTriggered();
+    void onDeleteGroupTriggered();
+    void onShowInfoTriggered();
+    void onDeleteContactTriggered();
+    void onJoinChatRoomRequested();         /** join chat room action is triggered */
+
+    void onAccountManagerReady(Tp::PendingOperation *op);
+    void onContactListClicked(const QModelIndex &index);
+    void onContactListDoubleClicked(const QModelIndex &index);
+    void onConnectionChanged(const Tp::ConnectionPtr &connection);
+    void onAccountConnectionStatusChanged(Tp::ConnectionStatus status);
+    void onCustomContextMenuRequested(const QPoint &point);
+
     void onAccountsPresenceStatusFiltered();
     void onPresencePublicationRequested(const Tp::Contacts &contacts);
-    void monitorPresence(const Tp::ConnectionPtr &connection);
     void onContactManagerStateChanged(Tp::ContactListState state);
     void onContactManagerStateChanged(const Tp::ContactManagerPtr &contactManager, Tp::ContactListState state);
     void onSwitchToFullView();
     void onSwitchToCompactView();
-    void onCreateNewGroup();
-    void onRenameGroup();
-    void onDeleteGroup();
+
+    void onGenericOperationFinished(Tp::PendingOperation *operation); /** called when a Tp::PendingOperation finishes. Used to check for errors */
+
+    void groupContacts(bool enabled);
+    void monitorPresence(const Tp::ConnectionPtr &connection);
 
 Q_SIGNALS:
     void enableOverlays(bool);
@@ -137,10 +137,9 @@ private:
 
     AccountsModel          *m_model;
     GroupsModel            *m_groupsModel;
-    AccountsFilterModel     *m_modelFilter;
+    AccountsFilterModel    *m_modelFilter;
     Tp::AccountManagerPtr   m_accountManager;
     KMenu                  *m_accountMenu;
-    KMenu                  *m_avatarButtonMenu;
     KSelectAction          *m_setStatusAction;
     ContactDelegate        *m_delegate;
     ContactDelegateCompact *m_compactDelegate;
diff --git a/main-widget.ui b/main-widget.ui
index 73c4333..7e97288 100644
--- a/main-widget.ui
+++ b/main-widget.ui
@@ -50,7 +50,7 @@
        </widget>
       </item>
       <item row="0" column="0" rowspan="3">
-       <widget class="QToolButton" name="m_userAccountIconButton">
+       <widget class="AvatarButton" name="m_avatarButton">
         <property name="minimumSize">
          <size>
           <width>64</width>
@@ -111,6 +111,11 @@
    <header>filter-bar.h</header>
    <container>1</container>
   </customwidget>
+  <customwidget>
+   <class>AvatarButton</class>
+   <extends>QToolButton</extends>
+   <header>avatar-button.h</header>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections/>

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list