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

List:       kde-commits
Subject:    playground/base/plasma/applets/networkmanager/settings/config
From:       Will Stephenson <wstephenson () kde ! org>
Date:       2009-07-28 8:45:13
Message-ID: 1248770713.726825.2381.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1003429 by wstephens:

Add UI and KConfigXT for configuring tray icon


 M  +25 -3     manageconnectionwidget.cpp  
 M  +8 -0      manageconnectionwidget.h  
 M  +4 -29     traysettings.ui  
 M  +95 -18    traysettingswidget.cpp  
 M  +7 -2      traysettingswidget.h  


--- trunk/playground/base/plasma/applets/networkmanager/settings/config/manageconnectionwidget.cpp \
#1003428:1003429 @@ -26,6 +26,7 @@
 #include <NetworkManager.h>
 
 #include <QDBusConnection>
+#include <QDBusInterface>
 #include <QDateTime>
 #include <QFile>
 #include <QMenu>
@@ -60,7 +61,7 @@
 K_EXPORT_PLUGIN( ManageConnectionWidgetFactory( "kcm_networkmanagement" ) )
 
 ManageConnectionWidget::ManageConnectionWidget(QWidget *parent, const QVariantList \
                &args)
-: KCModule( ManageConnectionWidgetFactory::componentData(), parent, args ), \
mCellularMenu(0), mVpnMenu(0), mEditor(new ConnectionEditor(this)) +: KCModule( \
ManageConnectionWidgetFactory::componentData(), parent, args ), mCellularMenu(0), \
mVpnMenu(0), mEditor(new ConnectionEditor(this)), mTraySettingsWidget(0)  {
     KGlobal::locale()->insertCatalog("libknmui");
     connect(mEditor, SIGNAL(connectionsChanged()), this, \
SLOT(restoreConnections())); @@ -99,9 +100,10 @@
     connect(mLastUsedTimer, SIGNAL(timeout()), SLOT(updateLastUsed()));
     mLastUsedTimer->start(1000 * 60);
 
-    TraySettingsWidget * tsw = new TraySettingsWidget(this);
+    mTraySettingsWidget  = new TraySettingsWidget(this);
+    connect(mTraySettingsWidget, SIGNAL(changed()), SLOT(otherSettingsChanged()));
 
-    mConnEditUi.tabWidget->addTab(tsw, i18nc("@title:tab tab containing general UI \
settings", "&Other Settings")); +    \
mConnEditUi.tabWidget->addTab(mTraySettingsWidget, i18nc("@title:tab tab containing \
general UI settings", "&Other Settings"));  
     setButtons(KCModule::Help | KCModule::Apply);
 }
@@ -260,6 +262,7 @@
 {
     // show connection settings widget for the active tab
     mEditor->addConnection(false, connectionTypeForCurrentIndex());
+    emit changed();
 }
 
 void ManageConnectionWidget::editClicked()
@@ -267,6 +270,7 @@
     //edit might be clicked on a system connection, in which case we need a \
connectionid for it  QTreeWidgetItem * item = selectedItem();
     editItem(item);
+    emit changed();
 }
 
 void ManageConnectionWidget::editItem(QTreeWidgetItem * item)
@@ -323,6 +327,7 @@
         mEditor->updateService();
         restoreConnections();
     }
+    emit changed();
 }
 
 Knm::Connection::Type ManageConnectionWidget::connectionTypeForCurrentIndex() const
@@ -384,7 +389,18 @@
 
 void ManageConnectionWidget::save()
 {
+    if (mTraySettingsWidget) {
+        QList<uint> iconInterfaceAllocations = \
mTraySettingsWidget->iconInterfaceAllocations(); +        \
KNetworkManagerServicePrefs::self()->setIconCount(iconInterfaceAllocations.count()); \
+        for (int i = 0; i < iconInterfaceAllocations.count(); ++i) { +            \
KNetworkManagerServicePrefs::self()->setIconTypes(i, iconInterfaceAllocations.at(i)); \
+        } +    }
+    KNetworkManagerServicePrefs::self()->writeConfig();
     KCModule::save();
+    QDBusInterface remoteApp("org.kde.knetworkmanager", "/tray",
+                                       "org.kde.knetworkmanager");
+    remoteApp.call("reloadConfig");
 }
 
 void ManageConnectionWidget::tabChanged(int index)
@@ -504,6 +520,7 @@
     updateLastUsed(mConnEditUi.listCellular);
     updateLastUsed(mConnEditUi.listVpn);
     updateLastUsed(mConnEditUi.listPppoe);
+
 }
 
 void ManageConnectionWidget::updateLastUsed(QTreeWidget * list)
@@ -516,4 +533,9 @@
     }
 }
 
+void ManageConnectionWidget::otherSettingsChanged()
+{
+    emit changed();
+}
+
 #include "manageconnectionwidget.moc"
--- trunk/playground/base/plasma/applets/networkmanager/settings/config/manageconnectionwidget.h \
#1003428:1003429 @@ -33,6 +33,8 @@
 class QTreeWidget;
 class QTreeWidgetItem;
 
+class TraySettingsWidget;
+
 class ManageConnectionWidget : public KCModule
 {
 Q_OBJECT
@@ -86,6 +88,11 @@
      * Update the relative last used labels (called once a minute on a timer, cheesy \
                I know)
      */
     void updateLastUsed();
+
+    /**
+     * Used by the tray settings widget to indicate when its unmanaged widgets \
change +     */
+    void otherSettingsChanged();
 private:
     /**
      * Get the connection type of the currently selected index
@@ -111,6 +118,7 @@
     ConnectionEditor * mEditor;
     QHash<QString,QTreeWidgetItem*> mUuidItemHash;
     QTimer * mLastUsedTimer;
+    TraySettingsWidget * mTraySettingsWidget;
 };
 
 #endif // NM07_MANAGE_CONNECTION_WIDGET_H
--- trunk/playground/base/plasma/applets/networkmanager/settings/config/traysettings.ui \
#1003428:1003429 @@ -35,24 +35,13 @@
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_7">
      <item>
-      <widget class="QTreeWidget" name="iconInterfaceTree">
+      <widget class="QListWidget" name="iconInterfaceList">
        <property name="dragDropMode">
         <enum>QAbstractItemView::InternalMove</enum>
        </property>
        <property name="alternatingRowColors">
         <bool>true</bool>
        </property>
-       <property name="rootIsDecorated">
-        <bool>false</bool>
-       </property>
-       <attribute name="headerVisible">
-        <bool>false</bool>
-       </attribute>
-       <column>
-        <property name="text">
-         <string>1</string>
-        </property>
-       </column>
       </widget>
      </item>
      <item>
@@ -60,32 +49,18 @@
        <item>
         <widget class="QPushButton" name="pbAddIcon">
          <property name="text">
-          <string>A&amp;dd icon</string>
+          <string>&amp;More Icons</string>
          </property>
         </widget>
        </item>
        <item>
-        <widget class="QPushButton" name="pbIconUp">
+        <widget class="QPushButton" name="pbRemoveIcon">
          <property name="text">
-          <string>Move u&amp;p</string>
+          <string>&amp;Fewer Icons</string>
          </property>
         </widget>
        </item>
        <item>
-        <widget class="QPushButton" name="pbMoveDown">
-         <property name="text">
-          <string>Move Do&amp;wn</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QPushButton" name="pushButton_4">
-         <property name="text">
-          <string>&amp;Remove icon</string>
-         </property>
-        </widget>
-       </item>
-       <item>
         <spacer name="verticalSpacer_3">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
--- trunk/playground/base/plasma/applets/networkmanager/settings/config/traysettingswidget.cpp \
#1003428:1003429 @@ -20,24 +20,28 @@
 
 #include "traysettingswidget.h"
 
-#include <QTreeWidget>
+#include <QListWidget>
 
 #include <KDebug>
+#include <KIcon>
 #include <KLocale>
 
 #include <solid/control/networkinterface.h>
 
 #include "knmserviceprefs.h"
 
-class IconTreeWidgetItem : public QTreeWidgetItem
+static const int IconInterfaceRole = 20118;
+
+class IconListWidgetItem : public QListWidgetItem
 {
 public:
-    IconTreeWidgetItem(QTreeWidget * parent, uint visibleNumber)
-    : QTreeWidgetItem(parent)
+    IconListWidgetItem(QListWidget * parent, uint visibleNumber)
+    : QListWidgetItem(parent)
     {
-        setText(0, i18nc("@item:inlistbox", "Icon %1", \
                QString::number(visibleNumber)));
-        setExpanded(true);
+        setText(i18nc("@item:inlistbox", "Icon %1", \
                QString::number(visibleNumber)));
         setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
+        setIcon(KIcon("networkmanager"));
+        setData(IconInterfaceRole, Solid::Control::NetworkInterface::UnknownType);
     }
 };
 
@@ -52,12 +56,19 @@
 
     for (uint i = 0; (i < m_iconCount && i < 5); ++i) {
 
-        IconTreeWidgetItem * item = new IconTreeWidgetItem(m_ui.iconInterfaceTree, \
i+1); +        IconListWidgetItem * item = new \
IconListWidgetItem(m_ui.iconInterfaceList, i+1); +        if (i == 0) {
+            m_firstIconItem = item;
+        }
 
-        readIconTypes(i, item);
+        readIconTypes(i, m_ui.iconInterfaceList);
     }
 
+    m_ui.pbRemoveIcon->setEnabled(m_iconCount > 1);
+
     connect(m_ui.pbAddIcon, SIGNAL(clicked()), SLOT(addIconClicked()));
+    connect(m_ui.pbRemoveIcon, SIGNAL(clicked()), SLOT(removeIconClicked()));
+    connect(m_ui.iconInterfaceList->model(), SIGNAL( rowsInserted ( const \
QModelIndex &, int, int)), SLOT(itemsMoved()));  }
 
 TraySettingsWidget::~TraySettingsWidget()
@@ -65,24 +76,66 @@
 
 }
 
-void TraySettingsWidget::readIconTypes(uint index, QTreeWidgetItem * item)
+QList<uint> TraySettingsWidget::iconInterfaceAllocations() const
 {
+    // iterate the list and OR together the interface types grouped under each icon, \
return +    // as a list of uints.
+    // Ignore any icons that are empty (have no interface types before the end of \
the list or the +    // next icon.
+    QList<uint> allocations;
+    for (int i = 0; i < m_ui.iconInterfaceList->count(); ++i) {
+        // is the item an icon or an interface type
+        QListWidgetItem * item = m_ui.iconInterfaceList->item(i);
+        if (item->data(IconInterfaceRole).toUInt() == \
Solid::Control::NetworkInterface::UnknownType) { +            // start ORing together \
the following interface types until we reach the end or +            // another icon
+            int allocation = 0;
+            QListWidgetItem * iconItem = 0;
+            while (++i < m_ui.iconInterfaceList->count()) {
+                iconItem = m_ui.iconInterfaceList->item(i);
+                if (iconItem->data(IconInterfaceRole).toUInt() == \
Solid::Control::NetworkInterface::UnknownType) { +                    // we peeked \
the next icon, but i will be incremented at the end of the outer +                    \
// loop so decrement it now +                    --i;
+                    break; // back to the outer loop
+                } else { // interface type, add to this allocation
+                    allocation |= iconItem->data(IconInterfaceRole).toUInt();
+                }
+            }
+
+            // save any allocation we made in the inner loop
+            if (allocation != 0) { // don't save empty sets
+                allocations.append(allocation);
+            }
+        }
+    }
+    kDebug() << allocations;
+    return allocations;
+}
+
+void TraySettingsWidget::readIconTypes(uint index, QListWidget* list)
+{
     Solid::Control::NetworkInterface::Types \
                iconTypes(KNetworkManagerServicePrefs::self()->iconTypes(index));
-    QTreeWidgetItem * childItem;
+    QListWidgetItem * childItem;
     if (iconTypes.testFlag(Solid::Control::NetworkInterface::Ieee8023)) {
-        childItem = new QTreeWidgetItem(item, QStringList(i18nc("@item:inlistbox", \
"Wired network interfaces"))); +        childItem = new \
QListWidgetItem(i18nc("@item:inlistbox", "Wired network interfaces"), list); +        \
childItem->setData(IconInterfaceRole, Solid::Control::NetworkInterface::Ieee8023);  }
     if (iconTypes.testFlag(Solid::Control::NetworkInterface::Ieee80211)) {
-        childItem = new QTreeWidgetItem(item, QStringList(i18nc("@item:inlistbox", \
"Wireless network interfaces"))); +        childItem = new \
QListWidgetItem(i18nc("@item:inlistbox", "Wireless network interfaces"), list); +     \
childItem->setData(IconInterfaceRole, Solid::Control::NetworkInterface::Ieee80211);  \
}  if (iconTypes.testFlag(Solid::Control::NetworkInterface::Serial)) {
-        childItem = new QTreeWidgetItem(item, QStringList(i18nc("@item:inlistbox", \
"DSL network devices"))); +        childItem = new \
QListWidgetItem(i18nc("@item:inlistbox", "DSL network devices"), list); +        \
childItem->setData(IconInterfaceRole, Solid::Control::NetworkInterface::Serial);  }
     if (iconTypes.testFlag(Solid::Control::NetworkInterface::Gsm)) {
-        childItem = new QTreeWidgetItem(item, QStringList(i18nc("@item:inlistbox", \
"GSM network devices"))); +        childItem = new \
QListWidgetItem(i18nc("@item:inlistbox", "GSM network devices"), list); +        \
childItem->setData(IconInterfaceRole, Solid::Control::NetworkInterface::Gsm);  }
     if (iconTypes.testFlag(Solid::Control::NetworkInterface::Cdma)) {
-        childItem = new QTreeWidgetItem(item, QStringList(i18nc("@item:inlistbox", \
"CDMA network devices"))); +        childItem = new \
QListWidgetItem(i18nc("@item:inlistbox", "CDMA network devices"), list); +        \
childItem->setData(IconInterfaceRole, Solid::Control::NetworkInterface::Cdma);  }
 
     if (childItem)
@@ -92,16 +145,40 @@
 
 void TraySettingsWidget::addIconClicked()
 {
-    if (m_iconCount < 4) {
-        new IconTreeWidgetItem(m_ui.iconInterfaceTree, ++m_iconCount);
+    if (m_iconCount < 5) {
+        new IconListWidgetItem(m_ui.iconInterfaceList, ++m_iconCount);
+        m_ui.pbRemoveIcon->setEnabled(true);
     } else {
         m_ui.pbAddIcon->setEnabled(false);
     }
+    emit changed();
 }
 
 void TraySettingsWidget::removeIconClicked()
 {
+    //iterate the items backwards and remove the first icon item found as long as it \
is not the +    //first one.
+    for (int i = m_ui.iconInterfaceList->count() - 1; i >= 0; --i) {
+        QListWidgetItem * item = m_ui.iconInterfaceList->item(i);
+        if (item) {
+            if (item->data(IconInterfaceRole).toUInt() == \
Solid::Control::NetworkInterface::UnknownType && item != m_firstIconItem) { +         \
m_ui.iconInterfaceList->takeItem(i); +                --m_iconCount;
+                m_ui.pbAddIcon->setEnabled(true);
+                break;
+            }
+        }
+    }
+    if (m_iconCount == 1) {
+        // removed the penultimate icon item, don't take any more
+        m_ui.pbRemoveIcon->setEnabled(false);
+    }
+    emit changed();
+}
 
+
+void TraySettingsWidget::itemsMoved()
+{
+    emit changed();
 }
-
 // vim: sw=4 sts=4 et tw=100
--- trunk/playground/base/plasma/applets/networkmanager/settings/config/traysettingswidget.h \
#1003428:1003429 @@ -25,7 +25,7 @@
 
 #include "ui_traysettings.h"
 
-class QTreeWidgetItem;
+class QListWidgetItem;
 
 class TraySettingsWidget : public QWidget
 {
@@ -33,13 +33,18 @@
 public:
     TraySettingsWidget(QWidget * parent = 0);
     virtual ~TraySettingsWidget();
+    QList<uint> iconInterfaceAllocations() const;
+signals:
+    void changed();
 protected Q_SLOTS:
     void addIconClicked();
     void removeIconClicked();
+    void itemsMoved();
 private:
-    void readIconTypes(uint index, QTreeWidgetItem * item);
+    void readIconTypes(uint index, QListWidget * item);
     Ui_TraySettings m_ui;
     uint m_iconCount;
+    QListWidgetItem * m_firstIconItem;
 };
 
 #endif // TRAYSETTINGSWIDGET_H


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

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