[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/applets/presence
From:       George Goldberg <grundleborg () googlemail ! com>
Date:       2008-07-11 8:55:58
Message-ID: 1215766558.904661.6912.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 830794 by gberg:

Major cleanup to make the code a bit tidier and to match the decibel coding style, \
since that is where this applet will most likely end up when it moves out of \
playground. Previously there was no consistent code style, just mess...


 M  +90 -68    presence.cpp  
 M  +35 -33    presence.h  


--- trunk/playground/base/plasma/applets/presence/presence.cpp #830793:830794
@@ -9,7 +9,7 @@
  *   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
+ *   GNU Library General Public License for more details
  *
  *   You should have received a copy of the GNU Library General Public
  *   License along with this program; if not, write to the
@@ -22,57 +22,73 @@
 #include <plasma/theme.h>
 #include <plasma/widgets/icon.h>
 
-#include <QtTapioca/PresenceState>
-
 #include <Decibel/Types>
 
-#include <QLabel>
-#include <QString>
-#include <QStandardItemModel>
-#include <QTreeView>
-#include <QHeaderView>
-#include <QWidget>
-#include <QList>
-#include <QVBoxLayout>
-
-#include <KLineEdit>
+#include <KColorScheme>
 #include <KDebug>
-#include <KColorScheme>
 #include <KIcon>
-#include <KColorScheme>
+#include <KLineEdit>
 
-Presence::Presence(QObject *parent, const QVariantList &args)
-    : PlasmaAppletDialog(parent, args),
+#include <QtTapioca/PresenceState>
+
+#include <QtCore/QList>
+#include <QtCore/QString>
+
+#include <QtGui/QHeaderView>
+#include <QtGui/QLabel>
+#include <QtGui/QStandardItemModel>
+#include <QtGui/QTreeView>
+#include <QtGui/QWidget>
+#include <QtGui/QVBoxLayout>
+
+PresenceApplet::PresenceApplet(QObject * parent, const QVariantList & args)
+  : PlasmaAppletDialog(parent, args),
+    m_engine(0),
+    m_colorScheme(0),
+    m_messageEdit(0),
+    m_masterIconLabel(0),
     m_accountsModel(0),
     m_accountsView(0),
-    m_messageEdit(0),
-    m_colorScheme(0),
-    m_masterIconLabel(0)
+    m_layout(0),
+    m_widget(0)
+{ }
+
+PresenceApplet::~PresenceApplet()
 {
-    m_layout = 0;
-    m_widget = 0;
+    delete m_colorScheme;
 }
 
-void Presence::initialize()
+void
+PresenceApplet::initialize()
 {
     kDebug() << "Initializing applet.";
 
     // Set up the color scheme.
-    m_colorScheme = new KColorScheme(QPalette::Active, KColorScheme::View, \
Plasma::Theme::defaultTheme()->colorScheme()); +    Q_ASSERT(!m_colorScheme);  // \
Pointer should still be assigned to 0. +    m_colorScheme = new \
KColorScheme(QPalette::Active,  +                                     \
KColorScheme::View, +                                     \
Plasma::Theme::defaultTheme()->colorScheme());  
     // Set up the icon.
+    Q_ASSERT(!m_icon);  // Pointer should still be assigned to 0.
     m_icon = new Plasma::Icon(KIcon("user-offline"), QString(), this);
 
     // The icon has been changed.
     iconChanged();
 
     // Set up the accounts model.
+    Q_ASSERT(!m_accountsModel);  //Pointer should still be assigned to 0.
     m_accountsModel = new QStandardItemModel(this);
     m_accountsModel->setColumnCount(4);
-    m_accountsModel->setHeaderData(1, Qt::Horizontal, QVariant("online?"), \
                Qt::DisplayRole);
-    m_accountsModel->setHeaderData(2, Qt::Horizontal, QVariant("status"), \
                Qt::DisplayRole);
-    m_accountsModel->setHeaderData(3, Qt::Horizontal, QVariant("message"), \
Qt::DisplayRole);  
+    m_accountsModel->setHeaderData(1, Qt::Horizontal,
+                                   QVariant("online?"), Qt::DisplayRole);
+    m_accountsModel->setHeaderData(2, Qt::Horizontal,
+                                   QVariant("status"), Qt::DisplayRole);
+    m_accountsModel->setHeaderData(3, Qt::Horizontal,
+                                   QVariant("message"), Qt::DisplayRole);
+
+    Q_ASSERT(!m_engine);  // Pointer should still be assigned to 0.
     m_engine = dataEngine("presence");
 
     QStringList sources = m_engine->sources();
@@ -81,27 +97,35 @@
         sourceAdded(source);
     }
 
-    connect(m_engine, SIGNAL(sourceAdded(QString)), this, \
                SLOT(sourceAdded(QString)));
-    connect(m_engine, SIGNAL(sourceRemoved(QString)), this, \
SLOT(sourceRemoved(QString))); +    connect(m_engine, SIGNAL(sourceAdded(QString)),
+            this, SLOT(sourceAdded(QString)));
+    connect(m_engine, SIGNAL(sourceRemoved(QString)),
+            this, SLOT(sourceRemoved(QString)));
 }
 
-QWidget * Presence::widget()
+QWidget *
+PresenceApplet::widget()
 {
     if(!m_widget)
     {
         // Set up the accounts view.
+        Q_ASSERT(!m_accountsView);  // Pointer should still be assigned to 0.
         m_accountsView = new QTreeView;
         m_accountsView->setModel(m_accountsModel);
         m_accountsView->header()->setVisible(true);
         m_accountsView->setColumnHidden(0, true);   //Hide the source id column
 
         // Make sure we have a masterIconPixmap.
+        Q_ASSERT(!m_masterIconLabel);  // Pointer should still be assigned to 0.
         m_masterIconLabel = new QLabel;
         iconChanged();
 
         // Set up the rest of the view/layout etc. stuff.
+        Q_ASSERT(!m_messageEdit);  // Pointer should still be assigned to 0.
         m_messageEdit = new KLineEdit;
 
+        Q_ASSERT(!m_widget);  // Pointer should still be assigned to 0.
+        Q_ASSERT(!m_layout);  // Pointer should still be assigned to 0.
         m_widget = new QWidget();
         m_layout = new QVBoxLayout(m_widget);
         m_layout->addWidget(m_masterIconLabel);
@@ -111,49 +135,36 @@
 
         // Apply the theme's color scheme to the widget.
         QPalette editPalette = m_widget->palette();
-        editPalette.setColor(QPalette::Window, m_colorScheme->background().color());
+        editPalette.setColor(QPalette::Window,
+                             m_colorScheme->background().color());
         m_widget->setPalette(editPalette);
     }
 
+    Q_ASSERT(m_widget);  // We must have a valid m_widget by now.
+
     return m_widget;
 }
 
-Presence::~Presence()
+void
+PresenceApplet::sourceAdded(const QString & source)
 {
-    delete m_colorScheme;
-}
-
-/*
-QSizeF Presence::contentSizeHint() const
-{
-    if (m_layout) {
-        kDebug() << "Returning the m_form size geometry";
-        return m_form->effectiveSizeHint(Qt::PreferredSize, contentSize());
-    }*/
-    /*
-     * this is the hardcoded default size
-     * of the plasmoid. (apparently not...)
-     */
-    // FIXME: change this to be a good size...
-    /*
-    return QSizeF(300, 300);
-}
-*/
-
-void Presence::sourceAdded(const QString& source)
-{
+    Q_ASSERT(m_engine);  // Engine must be valid.
     kDebug() << "started with source: " << source;
     m_engine->connectSource(source, this);
 }
 
 
-void Presence::sourceRemoved(const QString& source)
+void
+PresenceApplet::sourceRemoved(const QString & source)
 {
+    Q_ASSERT(m_engine);  // Engine must be valid.
     kDebug() << "started with source: " << source;
     m_engine->disconnectSource(source, this);
 }
 
-void Presence::dataUpdated(const QString &source, const Plasma::DataEngine::Data \
&data) +void
+PresenceApplet::dataUpdated(const QString & source,
+                            const Plasma::DataEngine::Data & data)
 {
     kDebug() << "Started with source: " << source; 
     /*
@@ -164,31 +175,36 @@
      * row. If not, then we create a new row with
      * the data for that source.
      */
-    QStandardItem *presence_type = new QStandardItem;
-    QStandardItem *presence_state = new QStandardItem;
-    QStandardItem *message = new QStandardItem;
+    QStandardItem * presence_type = new QStandardItem;
+    QStandardItem * presence_state = new QStandardItem;
+    QStandardItem * message = new QStandardItem;
+    // FIXME: Reimplement the lines below using new plasma API
     //online->setData(Plasma::Theme::self()->textColor(), Qt::ForegroundRole);
     //status->setData(Plasma::Theme::self()->textColor(), Qt::ForegroundRole);
     //message->setData(Plasma::Theme::self()->textColor(), Qt::ForegroundRole);
-    QtTapioca::PresenceState currentPresence = \
data.value("current_presence").value<QtTapioca::PresenceState>(); +    \
QtTapioca::PresenceState currentPresence +        = \
data.value("current_presence").value<QtTapioca::PresenceState>();  
-    presence_type->setData(static_cast<int>(currentPresence.type()), \
Qt::DisplayRole); +    \
presence_type->setData(static_cast<int>(currentPresence.type()), +                    \
Qt::DisplayRole);  presence_state->setData(currentPresence.name(), Qt::DisplayRole);
-    message->setData(data.value("decibel_presence_message").toString(), \
Qt::DisplayRole); +    \
message->setData(data.value("decibel_presence_message").toString(), +                 \
Qt::DisplayRole);  /*
      * so, we need to look in the first column
      * to see if we can find a row with that value
      */
+    Q_ASSERT(m_accountsModel);  // This must exist now.
     QList<QStandardItem*> items;
     items = m_accountsModel->findItems(source, Qt::MatchExactly, 0);
     int itemsCount = items.count();
-    if ( 0 == itemsCount )
+    if(0 == itemsCount)
     {
         /*
          * the source is new, so create
          * a new row for it.
          */
-        QStandardItem *id = new QStandardItem;
+        QStandardItem * id = new QStandardItem;
         id->setData(source, Qt::DisplayRole);
         QList<QStandardItem*> row;
         row.append(id);
@@ -197,7 +213,7 @@
         row.append(message);
         m_accountsModel->appendRow(row);
     }
-    else if ( 1 == itemsCount )
+    else if(1 == itemsCount)
     {
         /*
          * the data source is NOT new,
@@ -231,8 +247,11 @@
  * which icon we display. We must also check the presence message for each
  * account to see if we can display one overall presence message.
  */
-void Presence::updateMasterPresence()
+void
+PresenceApplet::updateMasterPresence()
 {
+    Q_ASSERT(m_accountsModel);
+    Q_ASSERT(m_icon);
     // Get data we can use to iterate over the contents of the accounts model.
     int rowCount = m_accountsModel->rowCount();
 
@@ -245,7 +264,7 @@
 
     bool statusMessagesAllTheSame = true;
     QString previousStatusMessage;
-    foreach(QString statusMessage, statusMessages)
+    foreach(const QString & statusMessage, statusMessages)
     {
         if(statusMessage == previousStatusMessage)
         {
@@ -367,7 +386,8 @@
     iconChanged();
 }
 
-void Presence::iconChanged()
+void
+PresenceApplet::iconChanged()
 {
     // The icon has been changed. We must update the pixmap of the icon for
     // display in the main widget.
@@ -377,4 +397,6 @@
     }
 }
 
+
 #include "presence.moc"
+
--- trunk/playground/base/plasma/applets/presence/presence.h #830793:830794
@@ -9,7 +9,7 @@
  *   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
+ *   GNU Library General Public License for more details
  *
  *   You should have received a copy of the GNU Library General Public
  *   License along with this program; if not, write to the
@@ -21,54 +21,56 @@
 #define PLASMA_APPLET_PRESENCE_H
 
 #include <plasmaappletdialog.h>
+
 #include <plasma/dataengine.h>
 
-#include <QGraphicsItem>
+class KColorScheme;
+class KLineEdit;
 
+class QLabel;
+class QStandardItemModel;
 class QString;
-class QStandardItemModel;
 class QTreeView;
 class QVBoxLayout;
 class QWidget;
-class QLabel;
 
-class KLineEdit;
-class KColorScheme;
-
-class Presence : public PlasmaAppletDialog
+class PresenceApplet : public PlasmaAppletDialog
 {
-        Q_OBJECT
-    public:
-        Presence(QObject *parent, const QVariantList &args);
-        ~Presence();
+    Q_OBJECT
 
-     //   QSizeF contentSizeHint() const;
-        QWidget * widget();
+public:
+    PresenceApplet(QObject * parent, const QVariantList & args);
+    ~PresenceApplet();
 
-    private slots:
-        void sourceAdded(const QString& source);
-        void sourceRemoved(const QString& source);
-        void dataUpdated(const QString &source, const Plasma::DataEngine::Data \
&data); +    QWidget * widget();
 
-    protected:
-        void initialize();
+protected:
+    void initialize();
 
-    private Q_SLOTS:
-        void iconChanged();
+private Q_SLOTS:
+    void dataUpdated(const QString & source,
+                     const Plasma::DataEngine::Data & data);
+    void sourceAdded(const QString & source);
+    void sourceRemoved(const QString & source);
 
-    private:
-        void updateMasterPresence();
+private:
+    void iconChanged();
+    void updateMasterPresence();
 
-        QVBoxLayout* m_layout;
-        Plasma::DataEngine* m_engine;
-        QStandardItemModel *m_accountsModel;
-        QTreeView *m_accountsView;
-        QWidget * m_widget;
-        KLineEdit *m_messageEdit;
-        KColorScheme *m_colorScheme;
-        QLabel *m_masterIconLabel;
+    Plasma::DataEngine * m_engine;
+
+    KColorScheme * m_colorScheme;
+    KLineEdit * m_messageEdit;
+
+    QLabel * m_masterIconLabel;
+    QStandardItemModel * m_accountsModel;
+    QTreeView * m_accountsView;
+    QVBoxLayout * m_layout;
+    QWidget * m_widget;
+
 };
 
-K_EXPORT_PLASMA_APPLET(presence, Presence)
+K_EXPORT_PLASMA_APPLET(presence, PresenceApplet)
 
 #endif
+


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic