[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/akonadi/resources/mbox
From: Bertjan Broeksema <b.broeksema () home ! nl>
Date: 2009-06-27 17:40:13
Message-ID: 1246124413.266381.1706.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 988291 by bbroeksema:
Implement compact feature in the configure dialog.
M +103 -1 compactpage.cpp
M +15 -2 compactpage.h
M +16 -6 compactpage.ui
M +1 -1 mboxresource.cpp
--- trunk/KDE/kdepim/akonadi/resources/mbox/compactpage.cpp #988290:988291
@@ -19,9 +19,111 @@
#include "compactpage.h"
-CompactPage::CompactPage(QWidget * parent) : QWidget( parent )
+#include <akonadi/collectionfetchjob.h>
+#include <akonadi/collectionmodifyjob.h>
+#include <libmbox/mbox.h>
+
+#include "deleteditemsattribute.h"
+
+using namespace Akonadi;
+
+CompactPage::CompactPage( const QString &collectionId, QWidget *parent )
+ : QWidget( parent )
+ , mCollectionId( collectionId )
{
ui.setupUi( this );
+
+ connect( ui.compactButton, SIGNAL( clicked() ), this, SLOT( compact() ) );
+
+ checkCollectionId();
}
+void CompactPage::checkCollectionId()
+{
+ if ( !mCollectionId.isEmpty() ) {
+ Collection collection;
+ collection.setRemoteId( mCollectionId );
+ CollectionFetchJob *fetchJob =
+ new CollectionFetchJob( collection, CollectionFetchJob::Base );
+
+ connect( fetchJob, SIGNAL( result( KJob* ) ),
+ this, SLOT( onCollectionFetchCheck( KJob* ) ) );
+ }
+}
+
+void CompactPage::compact()
+{
+ ui.compactButton->setEnabled( false );
+
+ Collection collection;
+ collection.setRemoteId( mCollectionId );
+ CollectionFetchJob *fetchJob =
+ new CollectionFetchJob( collection, CollectionFetchJob::Base );
+
+ connect( fetchJob, SIGNAL( result( KJob* ) ),
+ this, SLOT( onCollectionFetchCompact( KJob* ) ) );
+}
+
+void CompactPage::onCollectionFetchCheck( KJob *job )
+{
+ if ( job->error() ) {
+ // If we cannot fetch the collection, than also disable compacting.
+ ui.compactButton->setEnabled( false );
+ return;
+ }
+
+ CollectionFetchJob *fetchJob = dynamic_cast<CollectionFetchJob*>( job );
+ Q_ASSERT( fetchJob );
+ Q_ASSERT( fetchJob->collections().size() == 1 );
+
+ Collection mboxCollection = fetchJob->collections().first();
+ DeletedItemsAttribute *attr
+ = mboxCollection.attribute<DeletedItemsAttribute>( Akonadi::Entity::AddIfMissing \
); +
+ if ( attr->deletedItemOffsets().size() > 0 ) {
+ ui.compactButton->setEnabled( true );
+ ui.messageLabel->setText( i18np("(1 message marked for deletion)",
+ "(%1 messages marked for deletion)", attr->deletedItemOffsets().size() ) );
+ }
+}
+
+void CompactPage::onCollectionFetchCompact( KJob *job )
+{
+ if ( job->error() ) {
+ ui.messageLabel->setText( i18n( "Failed to fetch te collection." ) );
+ ui.compactButton->setEnabled( true );
+ return;
+ }
+
+ CollectionFetchJob *fetchJob = dynamic_cast<CollectionFetchJob*>( job );
+ Q_ASSERT( fetchJob );
+ Q_ASSERT( fetchJob->collections().size() == 1 );
+
+ Collection mboxCollection = fetchJob->collections().first();
+ DeletedItemsAttribute *attr
+ = mboxCollection.attribute<DeletedItemsAttribute>( Akonadi::Entity::AddIfMissing \
); +
+ MBox mbox;
+ // TODO: Set lock method.
+ if ( !mbox.load( KUrl( mCollectionId ).path() ) ) {
+ ui.messageLabel->setText( i18n( "Failed to load the mbox file" ) );
+ } else {
+ ui.messageLabel->setText( i18np( "(Deleting 1 message)",
+ "(Deleting %1 messages)", attr->deletedItemOffsets().size() ) );
+ // TODO: implement and connect to messageProcessed signal.
+ if ( mbox.purge( attr->deletedItemOffsets() ) ) {
+ mboxCollection.removeAttribute<DeletedItemsAttribute>();
+ CollectionModifyJob *modifyJob = new CollectionModifyJob( mboxCollection );
+ connect( modifyJob, SIGNAL( result( KJob * ) ),
+ this, SLOT( onCollectionModify( KJob *) ) );
+ } else
+ ui.messageLabel->setText( i18n( "Failed to compact the mbox file." ) );
+ }
+}
+
+void CompactPage::onCollectionModify( KJob *job )
+{
+ ui.messageLabel->setText( i18n( "MBox file compacted." ) );
+}
+
#include "compactpage.moc"
--- trunk/KDE/kdepim/akonadi/resources/mbox/compactpage.h #988290:988291
@@ -24,13 +24,26 @@
#include "ui_compactpage.h"
+class KJob;
+
class CompactPage : public QWidget
{
Q_OBJECT
+
public:
- CompactPage( QWidget *parent = 0 );
+ CompactPage( const QString &collectionId, QWidget *parent = 0 );
- private:
+ private slots:
+ void compact();
+ void onCollectionFetchCheck( KJob* );
+ void onCollectionFetchCompact( KJob* );
+ void onCollectionModify( KJob* );
+
+ private: // Methods
+ void checkCollectionId();
+
+ private: // Members
+ QString mCollectionId;
Ui::CompactPage ui;
};
--- trunk/KDE/kdepim/akonadi/resources/mbox/compactpage.ui #988290:988291
@@ -7,14 +7,14 @@
<x>0</x>
<y>0</y>
<width>299</width>
- <height>348</height>
+ <height>374</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
- <item row="0" column="0" colspan="3">
+ <item row="0" column="0" colspan="4">
<widget class="QLabel" name="label">
<property name="text">
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"> @@ -30,7 +30,7 @@
</property>
</widget>
</item>
- <item row="1" column="0" colspan="3">
+ <item row="1" column="0" colspan="4">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string/>
@@ -106,14 +106,17 @@
</property>
</spacer>
</item>
- <item row="3" column="1">
- <widget class="QPushButton" name="pushButton">
+ <item row="3" column="2">
+ <widget class="QPushButton" name="compactButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
<property name="text">
<string>&Compact now</string>
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="2" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -126,6 +129,13 @@
</property>
</spacer>
</item>
+ <item row="3" column="1">
+ <widget class="QLabel" name="messageLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
--- trunk/KDE/kdepim/akonadi/resources/mbox/mboxresource.cpp #988290:988291
@@ -81,7 +81,7 @@
void MboxResource::configure( WId windowId )
{
SingleFileResourceConfigDialog<Settings> dlg( windowId );
- dlg.addPage( "Compact frequency", new CompactPage() );
+ dlg.addPage( "Compact frequency", new CompactPage( Settings::self()->path() ) );
dlg.addPage( "Lock method", new LockMethodPage() );
dlg.setCaption( i18n("Select MBox file") );
if ( dlg.exec() == QDialog::Accepted ) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic