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

List:       kde-commits
Subject:    KDE/kdepim/kpilot/conduits/akonadibase
From:       Bertjan Broeksema <b.broeksema () home ! nl>
Date:       2009-06-01 21:13:08
Message-ID: 1243890788.087454.30097.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 976515 by bbroeksema:

Give the user a hint in the configuration dialog when an Akonadi resource is
configured that doesn't exist any longer.

CCBUG: 192187


 M  +108 -54   akonadi-setup-widget.ui  
 M  +40 -10    akonadisetupwidget.cc  


--- trunk/KDE/kdepim/kpilot/conduits/akonadibase/akonadi-setup-widget.ui \
#976514:976515 @@ -1,7 +1,8 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>AkonadiWidget</class>
- <widget class="QWidget" name="AkonadiWidget" >
-  <property name="geometry" >
+ <widget class="QWidget" name="AkonadiWidget">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
@@ -9,121 +10,127 @@
     <height>317</height>
    </rect>
   </property>
-  <layout class="QGridLayout" >
-   <item row="0" column="0" >
-    <layout class="QHBoxLayout" />
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <layout class="QHBoxLayout" name="hboxLayout">
+     <item>
+      <widget class="QLabel" name="fCollectionsLabel">
+       <property name="text">
+        <string>Select Collection:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
    </item>
-   <item row="1" column="0" >
-    <layout class="QHBoxLayout" >
-     <property name="spacing" >
-      <number>5</number>
-     </property>
-     <property name="leftMargin" >
-      <number>5</number>
-     </property>
+   <item row="2" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_3">
      <item>
-      <widget class="QLabel" name="fWarnIcon1" >
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+      <widget class="QLabel" name="fWarnIcon1">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
          <horstretch>1</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>ICON</string>
        </property>
-       <property name="alignment" >
+       <property name="alignment">
         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QLabel" name="fSelectionWarnLabel" >
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+      <widget class="QLabel" name="fSelectionWarnLabel">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
          <horstretch>8</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>No collection selected yet. Make sure you select a collection before \
synchronizing. If you do not see any collections in the combobox, make sure that \
Akonadi started and that there is a valid resource for this data type.</string>  \
                </property>
-       <property name="alignment" >
+       <property name="alignment">
         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
        </property>
-       <property name="wordWrap" >
+       <property name="wordWrap">
         <bool>true</bool>
        </property>
-       <property name="margin" >
+       <property name="margin">
         <number>5</number>
        </property>
-       <property name="indent" >
+       <property name="indent">
         <number>0</number>
        </property>
       </widget>
      </item>
     </layout>
    </item>
-   <item row="2" column="0" >
-    <layout class="QHBoxLayout" >
-     <property name="spacing" >
-      <number>5</number>
-     </property>
-     <property name="leftMargin" >
-      <number>5</number>
-     </property>
-     <property name="topMargin" >
-      <number>0</number>
-     </property>
+   <item row="3" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
      <item>
-      <widget class="QLabel" name="fWarnIcon2" >
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+      <widget class="QLabel" name="fWarnIcon2">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
          <horstretch>1</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>ICON</string>
        </property>
-       <property name="alignment" >
+       <property name="alignment">
         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QLabel" name="label_3" >
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+      <widget class="QLabel" name="label_3">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
          <horstretch>8</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>Do not change the collection once you have synced your device with \
one of the Akonadi Collections. There are currently no advanced checks in the code so \
prepare for the worst when you decide to do it anyway. We are working on this. Please \
contact us in #kpilot on irc.freenode.org if you have problems.</string>  </property>
-       <property name="alignment" >
+       <property name="alignment">
         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
        </property>
-       <property name="wordWrap" >
+       <property name="wordWrap">
         <bool>true</bool>
        </property>
-       <property name="margin" >
+       <property name="margin">
         <number>5</number>
        </property>
-       <property name="indent" >
+       <property name="indent">
         <number>0</number>
        </property>
       </widget>
      </item>
     </layout>
    </item>
-   <item row="3" column="0" >
+   <item row="5" column="0">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>505</width>
        <height>61</height>
@@ -131,6 +138,53 @@
      </property>
     </spacer>
    </item>
+   <item row="1" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="fErrorIcon">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+         <horstretch>1</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text">
+        <string>ERROR
+ICON</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="fNonExistingCollection">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+         <horstretch>8</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text">
+        <string>The previous configured Akonadi collection is invalid. You must \
select a valid Akonadi collection above and click apply before you can use this \
conduit. +</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+       </property>
+       <property name="wordWrap">
+        <bool>true</bool>
+       </property>
+       <property name="margin">
+        <number>5</number>
+       </property>
+       <property name="indent">
+        <number>0</number>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
   </layout>
  </widget>
  <resources/>
--- trunk/KDE/kdepim/kpilot/conduits/akonadibase/akonadisetupwidget.cc #976514:976515
@@ -30,26 +30,28 @@
 #include "akonadisetupwidget.h"
 
 #include <akonadi/control.h>
+#include <akonadi/collectionfetchjob.h>
 #include <akonadi/collectionmodel.h>
 #include <akonadi/collectionfilterproxymodel.h>
 
 #include "collectioncombobox.h"
 #include "options.h"
 
+using namespace Akonadi;
+
 class AkonadiSetupWidget::Private
 {
 public:
 	Private() 
 		: fCollectionFilterModel( 0L )
-		, fCollectionsLabel( 0L )
 		, fCollections( 0L )
 	{
 	}
 	
 	Ui::AkonadiWidget fUi;
 	Akonadi::CollectionFilterProxyModel* fCollectionFilterModel;
-	QLabel* fCollectionsLabel;
 	CollectionComboBox* fCollections;
+	Entity::Id fConfiguredCollection;
 	bool fCollectionModified;
 };
 
@@ -68,8 +70,6 @@
 	d->fCollections = new CollectionComboBox( this );
 	d->fCollections->setModel( d->fCollectionFilterModel );
 	
-	d->fCollectionsLabel = new QLabel( this );
-	
 	connect( d->fCollections, SIGNAL( selectionChanged( const Akonadi::Collection& ) )
 			,this , SLOT( changeCollection( const Akonadi::Collection& ) ) );
 	
@@ -77,10 +77,14 @@
 		KIcon( QLatin1String( "dialog-warning" ) ).pixmap( 32 ) );
 	d->fUi.fWarnIcon2->setPixmap( 
 		KIcon( QLatin1String( "dialog-warning" ) ).pixmap( 32 ) );
-	
-	d->fUi.hboxLayout->addWidget( d->fCollectionsLabel, 1 );
+  d->fUi.fErrorIcon->setPixmap(
+    KIcon( QLatin1String( "dialog-error" ) ).pixmap( 32 ) );
+
 	d->fUi.hboxLayout->addWidget( d->fCollections, 2 );
-  
+
+  d->fUi.fErrorIcon->setVisible(true);
+  d->fUi.fNonExistingCollection->setVisible(true);
+
   Akonadi::Control::widgetNeedsAkonadi( this );
 }
 
@@ -95,9 +99,13 @@
 	DEBUGKPILOT << "collection id: "<< col.id() << ", name: " << col.name()
 		    << ", resource: " << col.resource() << ", mimeType: " << col.mimeType();
 
-	if( col.id() >= 0 )
+	if( d->fConfiguredCollection != col.id() && col.id() >= 0 )
 	{
 		d->fCollectionModified = true;
+
+		d->fUi.fErrorIcon->setVisible(false);
+		d->fUi.fNonExistingCollection->setVisible(false);
+
 		d->fUi.fWarnIcon1->setVisible( false );
 		d->fUi.fSelectionWarnLabel->setVisible( false );
 		
@@ -121,8 +129,30 @@
 
 	DEBUGKPILOT << "request to set collection to id: " << id;
 
-	if( id >= 0 )
+	// This is a bit ugly but currently I see no other way how to fix this. We
+	// assume here that if the fetch job fails, the collection does not exist
+	// (anymore). The user probably has deleted the collection and created new
+	// ones, maybe even a new one for the same file. However in the latter case
+	// the resource gets a new ID so even though it is a resource for the same
+	// file the user has to update the configuration of KPilot.
+	// The CollectionModel loads asynchronous so checking if the collection model
+	// contains the id might fail even though the collection still exists.
+	// Therefore I use a synchronous fetchjob here to work around that problem and
+	// be a bit more sure that the collection actually does or does not exists.
+	CollectionFetchJob *job = new CollectionFetchJob( Collection( id ), \
CollectionFetchJob::Base ); +	if ( !job->exec() ) {
+		DEBUGKPILOT << "The collection does not exist." << id;
+		// Make clear to the user that the configured collection does not exist
+		// anymore.
+		d->fUi.fErrorIcon->setVisible(true);
+		d->fUi.fNonExistingCollection->setVisible(true);
+	}
+	else
 	{
+		d->fConfiguredCollection = id;
+		d->fUi.fErrorIcon->setVisible(false);
+		d->fUi.fNonExistingCollection->setVisible(false);
+
 		d->fUi.fWarnIcon1->setVisible( false );
 		d->fUi.fSelectionWarnLabel->setVisible( false );
 		d->fCollections->setSelectedCollection( id );
@@ -131,7 +161,7 @@
 
 void AkonadiSetupWidget::setCollectionLabel( const QString& label )
 {
-	d->fCollectionsLabel->setText( label );
+	d->fUi.fCollectionsLabel->setText( label );
 }
 
 void AkonadiSetupWidget::setMimeTypes( const QStringList& mimeTypes )


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

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