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

List:       kde-commits
Subject:    KDE/kdepim/akonadi/clients/akonadiconsole
From:       Volker Krause <vkrause () kde ! org>
Date:       2008-03-23 11:35:10
Message-ID: 1206272110.242816.28709.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 789143 by vkrause:

Add attribute viewer/editor.


 M  +55 -0     browserwidget.cpp  
 M  +4 -0      browserwidget.h  
 M  +40 -5     browserwidget_contentview.ui  


--- trunk/KDE/kdepim/akonadi/clients/akonadiconsole/browserwidget.cpp #789142:789143
@@ -21,6 +21,7 @@
 #include "collectionattributespage.h"
 #include "collectioninternalspage.h"
 
+#include <akonadi/attributefactory.h>
 #include <akonadi/job.h>
 #include <akonadi/collectionview.h>
 #include <akonadi/item.h>
@@ -47,6 +48,7 @@
 #include <QVBoxLayout>
 #include <QStackedWidget>
 #include <QtGui/QSortFilterProxyModel>
+#include <QStandardItemModel>
 
 using namespace Akonadi;
 
@@ -100,6 +102,9 @@
   splitter2->addWidget( contentViewParent );
   contentUi.partCombo->addItem( "Body" );
 
+  connect( contentUi.attrAddButton, SIGNAL(clicked()), SLOT(addAttribute()) );
+  connect( contentUi.attrDeleteButton, SIGNAL(clicked()), SLOT(delAttribute()) );
+
   CollectionPropertiesDialog::registerPage( new CollectionAttributePageFactory() );
   CollectionPropertiesDialog::registerPage( new CollectionInternalsPageFactory() );
 }
@@ -120,6 +125,7 @@
 
   ItemFetchJob *job = new ItemFetchJob( item, this );
   job->addFetchPart( Item::PartBody );
+  job->fetchAllParts();
   connect( job, SIGNAL(result(KJob*)), SLOT(itemFetchDone(KJob*)) );
   job->start();
 }
@@ -154,6 +160,22 @@
     foreach ( const Item::Flag &f, item.flags() )
       flags << QString::fromUtf8( f );
     contentUi.flags->setItems( flags );
+
+    Attribute::List list = item.attributes();
+    mAttrModel = new QStandardItemModel( list.count(), 2 );
+    QStringList labels;
+    labels << i18n( "Attribute" ) << i18n( "Value" );
+    mAttrModel->setHorizontalHeaderLabels( labels );
+    for ( int i = 0; i < list.count(); ++i ) {
+      QModelIndex index = mAttrModel->index( i, 0 );
+      Q_ASSERT( index.isValid() );
+      mAttrModel->setData( index, QString::fromLatin1( list[i]->type() ) );
+      index = mAttrModel->index( i, 1 );
+      Q_ASSERT( index.isValid() );
+      mAttrModel->setData( index, QString::fromLatin1( list[i]->toByteArray() ) );
+      mAttrModel->itemFromIndex( index )->setFlags( Qt::ItemIsEditable | \
mAttrModel->flags( index ) ); +    }
+    contentUi.attrView->setModel( mAttrModel );
   }
 }
 
@@ -188,6 +210,19 @@
   foreach ( const QString s, contentUi.flags->items() )
     item.setFlag( s.toUtf8() );
   item.addPart( Item::PartBody, data );
+
+  item.clearAttributes();
+  for ( int i = 0; i < mAttrModel->rowCount(); ++i ) {
+    const QModelIndex typeIndex = mAttrModel->index( i, 0 );
+    Q_ASSERT( typeIndex.isValid() );
+    const QModelIndex valueIndex = mAttrModel->index( i, 1 );
+    Q_ASSERT( valueIndex.isValid() );
+    Attribute* attr = AttributeFactory::createAttribute( mAttrModel->data( typeIndex \
).toString().toLatin1() ); +    Q_ASSERT( attr );
+    attr->setData( mAttrModel->data( valueIndex ).toString().toLatin1() );
+    item.addAttribute( attr );
+  }
+
   ItemModifyJob *store = new ItemModifyJob( item, this );
   store->storePayload();
   connect( store, SIGNAL(result(KJob*)), SLOT(saveResult(KJob*)) );
@@ -210,4 +245,24 @@
   }
 }
 
+void BrowserWidget::addAttribute()
+{
+  if ( contentUi.attrName->text().isEmpty() )
+    return;
+  const int row = mAttrModel->rowCount();
+  mAttrModel->insertRow( row );
+  QModelIndex index = mAttrModel->index( row, 0 );
+  Q_ASSERT( index.isValid() );
+  mAttrModel->setData( index, contentUi.attrName->text() );
+  contentUi.attrName->clear();
+}
+
+void BrowserWidget::delAttribute()
+{
+  QModelIndexList selection = contentUi.attrView->selectionModel()->selectedRows();
+  if ( selection.count() != 1 )
+    return;
+  mAttrModel->removeRow( selection.first().row() );
+}
+
 #include "browserwidget.moc"
--- trunk/KDE/kdepim/akonadi/clients/akonadiconsole/browserwidget.h #789142:789143
@@ -30,6 +30,7 @@
 
 class QModelIndex;
 class QItemSelectionModel;
+class QStandardItemModel;
 
 class KJob;
 class KXmlGuiWindow;
@@ -58,6 +59,8 @@
     void modelChanged();
     void save();
     void saveResult( KJob* job );
+    void addAttribute();
+    void delAttribute();
 
   private:
     Akonadi::CollectionModel *mCollectionModel;
@@ -67,6 +70,7 @@
     Ui::ContentViewWidget contentUi;
     Akonadi::Collection::Id mCurrentCollection;
     Akonadi::Item mCurrentItem;
+    QStandardItemModel *mAttrModel;
 };
 
 #endif
--- trunk/KDE/kdepim/akonadi/clients/akonadiconsole/browserwidget_contentview.ui \
#789142:789143 @@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>507</width>
-    <height>438</height>
+    <height>496</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout_2" >
@@ -21,7 +21,7 @@
         <x>0</x>
         <y>0</y>
         <width>487</width>
-        <height>352</height>
+        <height>410</height>
        </rect>
       </property>
       <attribute name="title" >
@@ -42,7 +42,7 @@
             <x>0</x>
             <y>0</y>
             <width>479</width>
-            <height>344</height>
+            <height>402</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_2" >
@@ -77,13 +77,48 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="tab_4" >
+      <attribute name="title" >
+       <string>Attributes</string>
+      </attribute>
+      <layout class="QGridLayout" name="gridLayout_4" >
+       <item row="0" column="0" colspan="3" >
+        <widget class="QTreeView" name="attrView" >
+         <property name="rootIsDecorated" >
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0" >
+        <widget class="KLineEdit" name="attrName" >
+         <property name="clickMessage" >
+          <string>New Attribute</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1" >
+        <widget class="KPushButton" name="attrAddButton" >
+         <property name="text" >
+          <string>&amp;Add</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="2" >
+        <widget class="KPushButton" name="attrDeleteButton" >
+         <property name="text" >
+          <string>&amp;Delete</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
      <widget class="QWidget" name="tab_2" >
       <property name="geometry" >
        <rect>
         <x>0</x>
         <y>0</y>
         <width>487</width>
-        <height>352</height>
+        <height>410</height>
        </rect>
       </property>
       <attribute name="title" >
@@ -134,7 +169,7 @@
         <x>0</x>
         <y>0</y>
         <width>487</width>
-        <height>352</height>
+        <height>410</height>
        </rect>
       </property>
       <attribute name="title" >


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

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