Branch 'kolab/integration/4.13.0' - 2 commits - incidenceeditor-ng/incidencecategories.cpp kmail/CMakeLists.txt kmail/kmmainwidget.cpp kmail/tag libkdepim/widgets mailcommon/tag

Christian Mollekopf mollekopf at kolabsys.com
Thu Jan 29 10:40:02 CET 2015


 incidenceeditor-ng/incidencecategories.cpp |    2 
 kmail/CMakeLists.txt                       |    1 
 kmail/kmmainwidget.cpp                     |    9 +
 kmail/tag/tagselectdialog.cpp              |  148 -----------------------------
 kmail/tag/tagselectdialog.h                |   64 ------------
 libkdepim/widgets/tagwidgets.cpp           |    4 
 mailcommon/tag/tag.cpp                     |   11 +-
 7 files changed, 19 insertions(+), 220 deletions(-)

New commits:
commit 3c9c66415ac7968f530eb619ed6a62a12d3e26cc
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Wed Jan 28 02:35:19 2015 +0100

    Use Akonadi::TagSelectionDialog instead of homebrew dialog

diff --git a/kmail/CMakeLists.txt b/kmail/CMakeLists.txt
index dfb0ef1..94db692 100644
--- a/kmail/CMakeLists.txt
+++ b/kmail/CMakeLists.txt
@@ -154,7 +154,6 @@ if (KDEPIM_BUILD_DESKTOP)
      tag/tagactionmanager.cpp
      foldershortcutactionmanager.cpp
      job/addressvalidationjob.cpp
-     tag/tagselectdialog.cpp
      job/createnewcontactjob.cpp
      job/addemailtoexistingcontactjob.cpp
      widgets/vacationscriptindicatorwidget.cpp
diff --git a/kmail/kmmainwidget.cpp b/kmail/kmmainwidget.cpp
index c943887..48eb08b 100644
--- a/kmail/kmmainwidget.cpp
+++ b/kmail/kmmainwidget.cpp
@@ -52,7 +52,6 @@ using KSieveUi::SieveDebugDialog;
 #include "collectionpage/collectionshortcutpage.h"
 #include "collectionpage/collectionviewpage.h"
 #include "collectionpage/collectionmailinglistpage.h"
-#include "tag/tagselectdialog.h"
 #include "archivemailagentinterface.h"
 #include "job/createnewcontactjob.h"
 #include "sendlateragentinterface.h"
@@ -132,6 +131,7 @@ using KSieveUi::SieveDebugDialog;
 #include <akonadi/collectiondeletejob.h>
 #include <akonadi/dbusconnectionpool.h>
 #include <Akonadi/CachePolicy>
+#include <Akonadi/TagSelectionDialog>
 
 #include <kpimidentities/identity.h>
 #include <kpimidentities/identitymanager.h>
@@ -2058,9 +2058,12 @@ void KMMainWidget::slotSelectMoreMessageTagList()
     if ( selectedMessages.isEmpty() )
         return;
 
-    TagSelectDialog dlg( this, selectedMessages.count(), selectedMessages.first() );
+    TagSelectionDialog dlg(this);
+    if (selectedMessages.count() == 1) {
+        dlg.setSelection(selectedMessages.first().tags());
+    }
     if ( dlg.exec() ) {
-        const Akonadi::Tag::List lst = dlg.selectedTag();
+        const Akonadi::Tag::List lst = dlg.selection();
 
         KMCommand *command = new KMSetTagCommand( lst, selectedMessages, KMSetTagCommand::CleanExistingAndAddNew );
         command->start();
diff --git a/kmail/tag/tagselectdialog.cpp b/kmail/tag/tagselectdialog.cpp
deleted file mode 100644
index 013fd63..0000000
--- a/kmail/tag/tagselectdialog.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2011, 2012, 2013 Montel Laurent <montel at kde.org>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; version 2 of the License
- *
- *  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.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- *  In addition, as a special exception, the copyright holders give
- *  permission to link the code of this program with any edition of
- *  the Qt library by Trolltech AS, Norway (or with modified versions
- *  of Qt that use the same license as Qt), and distribute linked
- *  combinations including the two.  You must obey the GNU General
- *  Public License in all respects for all of the code used other than
- *  Qt.  If you modify this file, you may extend this exception to
- *  your version of the file, but you are not obligated to do so.  If
- *  you do not wish to do so, delete this exception statement from
- *  your version.
- */
-
-#include "tagselectdialog.h"
-#include "tag.h"
-#include "kmkernel.h"
-
-#include <mailcommon/tag/addtagdialog.h>
-
-#include <KListWidgetSearchLine>
-#include <KLocalizedString>
-
-#include <QGridLayout>
-#include <QListWidget>
-#include <Akonadi/TagFetchJob>
-#include <Akonadi/TagFetchScope>
-#include <Akonadi/TagAttribute>
-
-using namespace KMail;
-
-TagSelectDialog::TagSelectDialog( QWidget * parent, int numberOfSelectedMessages, const Akonadi::Item &selectedItem)
-    : KDialog( parent ),
-      mNumberOfSelectedMessages(numberOfSelectedMessages),
-      mSelectedItem(selectedItem)
-{
-    setCaption( i18n( "Select Tags" ) );
-    setButtons( User1|Ok|Cancel );
-    setButtonText(User1, i18n("Add new tag..."));
-    setDefaultButton( Ok );
-    setModal( true );
-
-    QWidget *mainWidget = new QWidget( this );
-    QGridLayout *mainLayout = new QGridLayout( mainWidget );
-    mainLayout->setSpacing( KDialog::spacingHint() );
-    mainLayout->setMargin( KDialog::marginHint() );
-    setMainWidget( mainWidget );
-
-    mListTag = new QListWidget( this );
-    KListWidgetSearchLine *listWidgetSearchLine = new KListWidgetSearchLine(this,mListTag);
-    listWidgetSearchLine->setClickMessage(i18n("Search tag"));
-    listWidgetSearchLine->setClearButtonShown(true);
-
-    mainLayout->addWidget(listWidgetSearchLine);
-    mainLayout->addWidget( mListTag );
-
-    createTagList();
-    connect(this, SIGNAL(user1Clicked()), SLOT(slotAddNewTag()));
-
-    KConfigGroup group( KMKernel::self()->config(), "TagSelectDialog" );
-    const QSize size = group.readEntry( "Size", QSize(500, 300) );
-    if ( size.isValid() ) {
-        resize( size );
-    }
-}
-
-TagSelectDialog::~TagSelectDialog()
-{
-    KConfigGroup group( KMKernel::self()->config(), "TagSelectDialog" );
-    group.writeEntry( "Size", size() );
-}
-
-void TagSelectDialog::slotAddNewTag()
-{
-    QPointer<MailCommon::AddTagDialog> dialog = new MailCommon::AddTagDialog(QList<KActionCollection*>(), this);
-    dialog->setTags(mTagList);
-    if ( dialog->exec() ) {
-        mListTag->clear();
-        mTagList.clear();
-        createTagList();
-    }
-    delete dialog;
-}
-
-void TagSelectDialog::createTagList()
-{
-    Akonadi::TagFetchJob *fetchJob = new Akonadi::TagFetchJob(this);
-    fetchJob->fetchScope().fetchAttribute<Akonadi::TagAttribute>();
-    connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(slotTagsFetched(KJob*)));
-}
-
-void TagSelectDialog::slotTagsFetched(KJob *job)
-{
-    if (job->error()) {
-        kWarning() << "Failed to load tags " << job->errorString();
-        return;
-    }
-    Akonadi::TagFetchJob *fetchJob = static_cast<Akonadi::TagFetchJob*>(job);
-
-    foreach( const Akonadi::Tag &akonadiTag, fetchJob->tags() ) {
-        mTagList.append( MailCommon::Tag::fromAkonadi( akonadiTag ) );
-    }
-
-    qSort( mTagList.begin(), mTagList.end(), MailCommon::Tag::compare );
-
-    foreach( const MailCommon::Tag::Ptr &tag, mTagList ) {
-        QListWidgetItem *item = new QListWidgetItem(KIcon(tag->iconName), tag->tagName, mListTag );
-        item->setData(UrlTag, tag->tag().url().url() );
-        item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
-        item->setCheckState( Qt::Unchecked );
-        mListTag->addItem( item );
-
-        if ( mNumberOfSelectedMessages == 1 ) {
-            const bool hasTag = mSelectedItem.hasTag( tag->tag() );
-            item->setCheckState( hasTag ? Qt::Checked : Qt::Unchecked );
-        } else {
-            item->setCheckState( Qt::Unchecked );
-        }
-    }
-}
-
-Akonadi::Tag::List TagSelectDialog::selectedTag() const
-{
-    Akonadi::Tag::List lst;
-    const int numberOfItems( mListTag->count() );
-    for ( int i = 0; i< numberOfItems;++i ) {
-        QListWidgetItem *item = mListTag->item( i );
-        if ( item->checkState() == Qt::Checked ) {
-            lst.append( Akonadi::Tag::fromUrl( item->data(UrlTag).toString() ) );
-        }
-    }
-    qDebug()<<" lst"<<lst;
-    return lst;
-}
diff --git a/kmail/tag/tagselectdialog.h b/kmail/tag/tagselectdialog.h
deleted file mode 100644
index a373520..0000000
--- a/kmail/tag/tagselectdialog.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2011, 2012, 2013 Montel Laurent <montel at kde.org>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; version 2 of the License
- *
- *  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.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- *  In addition, as a special exception, the copyright holders give
- *  permission to link the code of this program with any edition of
- *  the Qt library by Trolltech AS, Norway (or with modified versions
- *  of Qt that use the same license as Qt), and distribute linked
- *  combinations including the two.  You must obey the GNU General
- *  Public License in all respects for all of the code used other than
- *  Qt.  If you modify this file, you may extend this exception to
- *  your version of the file, but you are not obligated to do so.  If
- *  you do not wish to do so, delete this exception statement from
- *  your version.
- */
-
-#ifndef TAGSELECTDIALOG_H
-#define TAGSELECTDIALOG_H
-
-#include <KDialog>
-#include <Akonadi/Item>
-#include <Akonadi/Tag>
-#include "tag.h"
-
-class QListWidget;
-class TagSelectDialog : public KDialog
-{
-    Q_OBJECT
-public:
-    explicit TagSelectDialog( QWidget * parent, int numberOfSelectedMessages, const Akonadi::Item &selectedItem );
-    ~TagSelectDialog();
-    Akonadi::Tag::List selectedTag() const;
-
-private Q_SLOTS:
-    void slotAddNewTag();
-    void slotTagsFetched(KJob*);
-
-private:
-    void createTagList();
-    enum ItemType {
-        UrlTag = Qt::UserRole + 1
-    };
-    int mNumberOfSelectedMessages;
-    Akonadi::Item mSelectedItem;
-
-    QList<MailCommon::Tag::Ptr> mTagList;
-    QListWidget *mListTag;
-};
-
-
-#endif /* TAGSELECTDIALOG_H */
-


commit 310ed0be366459376c8a803c9d3bdcf1a1ceb7a3
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Wed Jan 28 02:08:09 2015 +0100

    Add GENERIC as default new tag type

diff --git a/incidenceeditor-ng/incidencecategories.cpp b/incidenceeditor-ng/incidencecategories.cpp
index 8d13d58..29b6b0e 100644
--- a/incidenceeditor-ng/incidencecategories.cpp
+++ b/incidenceeditor-ng/incidencecategories.cpp
@@ -103,7 +103,7 @@ void IncidenceCategories::printDebugInfo() const
 void IncidenceCategories::checkForUnknownCategories( const QStringList &categoriesToCheck )
 {
   foreach ( const QString &category, categoriesToCheck ) {
-    Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag(category), this);
+    Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag::genericTag(category), this);
     tagCreateJob->setMergeIfExisting(true);
     //TODO add the missing tags to the item and add them to the list of selected tags in the widget
   }
diff --git a/libkdepim/widgets/tagwidgets.cpp b/libkdepim/widgets/tagwidgets.cpp
index f2e4a59..2c516e7 100644
--- a/libkdepim/widgets/tagwidgets.cpp
+++ b/libkdepim/widgets/tagwidgets.cpp
@@ -59,7 +59,7 @@ void TagWidget::setSelection(const QStringList &tagNames)
     mCachedTagNames = tagNames;
     foreach (const QString &name, tagNames) {
       //TODO fetch by GID instead, we don't really want to create tags here
-      Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag(name), this);
+      Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag::genericTag(name), this);
       tagCreateJob->setMergeIfExisting(true);
       connect(tagCreateJob, SIGNAL(result(KJob*)), this, SLOT(onTagCreated(KJob*)));
     }
@@ -93,7 +93,7 @@ void TagSelectionDialog::setSelection(const QStringList &tagNames)
     mTagList.clear();
     foreach (const QString &name, tagNames) {
       //TODO fetch by GID instead, we don't really want to create tags here
-      Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag(name), this);
+      Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag::genericTag(name), this);
       tagCreateJob->setMergeIfExisting(true);
       connect(tagCreateJob, SIGNAL(result(KJob*)), this, SLOT(onTagCreated(KJob*)));
     }
diff --git a/mailcommon/tag/tag.cpp b/mailcommon/tag/tag.cpp
index 5752ac4..e3a09f4 100644
--- a/mailcommon/tag/tag.cpp
+++ b/mailcommon/tag/tag.cpp
@@ -22,6 +22,7 @@
 #include <Akonadi/Tag>
 #include <Akonadi/TagAttribute>
 
+#include <QUuid>
 #include <QDebug>
 
 using namespace MailCommon;
@@ -66,7 +67,15 @@ Tag::Ptr Tag::fromAkonadi(const Akonadi::Tag& akonadiTag)
 
 Akonadi::Tag Tag::saveToAkonadi(Tag::SaveFlags saveFlags) const
 {
-    Akonadi::Tag tag( tagName );
+    Akonadi::Tag tag = mTag;
+    if (tag.gid().isEmpty()) {
+        tag.setGid(QUuid::createUuid().toByteArray().mid(1, 36));
+    }
+    if (isImmutable) {
+        tag.setType(Akonadi::Tag::PLAIN);
+    } else {
+        tag.setType(Akonadi::Tag::GENERIC);
+    }
     Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>(Akonadi::AttributeEntity::AddIfMissing);
     attr->setDisplayName( tagName );
     attr->setIconName( iconName );




More information about the commits mailing list