diff --git a/incidenceeditor-ng/incidencecategories.cpp b/incidenceeditor-ng/incidencecategories.cpp index beda0c9bd2..6ea396343e 100644 --- a/incidenceeditor-ng/incidencecategories.cpp +++ b/incidenceeditor-ng/incidencecategories.cpp @@ -1,139 +1,142 @@ /* Copyright (c) 2010 Bertjan Broeksema Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "incidencecategories.h" #include "editorconfig.h" #include "ui_dialogdesktop.h" #include #include #include #include #include using namespace IncidenceEditorNG; IncidenceCategories::IncidenceCategories( Ui::EventOrTodoDesktop *ui ) : mUi( ui ) { setObjectName( "IncidenceCategories" ); connect( mUi->mTagWidget, SIGNAL(selectionChanged(Akonadi::Tag::List)), SLOT(onSelectionChanged(Akonadi::Tag::List)) ); } void IncidenceCategories::onSelectionChanged(const Akonadi::Tag::List &list) { mSelectedTags = list; mDirty = true; checkDirtyStatus(); } void IncidenceCategories::load( const KCalCore::Incidence::Ptr &incidence ) { mLoadedIncidence = incidence; mDirty = false; if ( mLoadedIncidence ) { checkForUnknownCategories( mLoadedIncidence->categories() ); } else { mSelectedTags.clear(); } mWasDirty = false; } void IncidenceCategories::load( const Akonadi::Item &item ) { mSelectedTags = item.tags(); mUi->mTagWidget->setSelection(item.tags()); } void IncidenceCategories::save( const KCalCore::Incidence::Ptr &incidence ) { Q_ASSERT( incidence ); incidence->setCategories( categories() ); } void IncidenceCategories::save( Akonadi::Item &item ) { if (item.tags() != mSelectedTags) { item.setTags(mSelectedTags); } } QStringList IncidenceCategories::categories() const { QStringList list; Q_FOREACH (const Akonadi::Tag &tag, mSelectedTags) { list << tag.name(); } return list; } bool IncidenceCategories::isDirty() const { return mDirty; } void IncidenceCategories::printDebugInfo() const { kDebug() << "mSelectedCategories = " << categories(); kDebug() << "mLoadedIncidence->categories() = " << mLoadedIncidence->categories(); } void IncidenceCategories::checkForUnknownCategories( const QStringList &categoriesToCheck ) { Akonadi::TagFetchJob *fetchJob = new Akonadi::TagFetchJob(); - fetchJob->setProperty("categoriesToCheck", categoriesToCheck); + mCategoriesToCheck = categoriesToCheck; connect(fetchJob, SIGNAL(tagsReceived(Akonadi::Tag::List)), this, SLOT(onTagsReceived(Akonadi::Tag::List))); + connect(fetchJob, SIGNAL(result(KJob *)), this, SLOT(onTagsFetchResult())); } void IncidenceCategories::onTagsReceived(const Akonadi::Tag::List &tags) { - QStringList tagsToCheck = sender()->property("categoriesToCheck").toStringList(); foreach (const Akonadi::Tag &tag, tags) { - if (tagsToCheck.contains(tag.gid()) || tagsToCheck.contains(tag.name())) { + if (mCategoriesToCheck.contains(tag.gid()) || mCategoriesToCheck.contains(tag.name())) { mSelectedTags << tag; } - tagsToCheck.removeAll(tag.gid()); - tagsToCheck.removeAll(tag.name()); + mCategoriesToCheck.removeAll(tag.gid()); + mCategoriesToCheck.removeAll(tag.name()); } mUi->mTagWidget->setSelection(mSelectedTags); +} - foreach ( const QString &category, tagsToCheck ) { +void IncidenceCategories::onTagsFetchResult() +{ + foreach ( const QString &category, mCategoriesToCheck ) { kDebug() << "Creating tag: " << category; Akonadi::Tag tag = Akonadi::Tag::genericTag(category); tag.setGid(category.toUtf8()); Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(tag, this); connect(tagCreateJob, SIGNAL(result(KJob*)), this, SLOT(onTagCreated(KJob*))); tagCreateJob->setMergeIfExisting(true); } } void IncidenceCategories::onTagCreated(KJob *job) { const Akonadi::Tag createdTag = static_cast(job)->tag(); kDebug() << "Created tag: " << createdTag; mSelectedTags << createdTag; mUi->mTagWidget->setSelection(mSelectedTags); } diff --git a/incidenceeditor-ng/incidencecategories.h b/incidenceeditor-ng/incidencecategories.h index 66e9f01afe..3c87c99b83 100644 --- a/incidenceeditor-ng/incidencecategories.h +++ b/incidenceeditor-ng/incidencecategories.h @@ -1,75 +1,77 @@ /* Copyright (c) 2010 Bertjan Broeksema Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef INCIDENCEEDITOR_INCIDENCECATEGORIES_H #define INCIDENCEEDITOR_INCIDENCECATEGORIES_H #include "incidenceeditor-ng.h" namespace Ui { class EventOrTodoDesktop; class EventOrTodoMore; } namespace IncidenceEditorNG { class INCIDENCEEDITORS_NG_EXPORT IncidenceCategories : public IncidenceEditor { Q_OBJECT public: explicit IncidenceCategories( Ui::EventOrTodoDesktop *ui ); virtual void load( const KCalCore::Incidence::Ptr &incidence ); virtual void load( const Akonadi::Item &item ); virtual void save( const KCalCore::Incidence::Ptr &incidence ); virtual void save( Akonadi::Item &item ); /** * Returns the list of currently selected categories. */ QStringList categories() const; virtual bool isDirty() const; /**reimp*/ void printDebugInfo() const; private slots: void onSelectionChanged(const Akonadi::Tag::List &); + void onTagsFetchResult(); void onTagsReceived(const Akonadi::Tag::List &); void onTagCreated(KJob *job); private: /** If the incidence comes from outside of KDE it can contain unknown categories. * KOrganizer usually checks for these, but it can happen that it checks before the * items are in the ETM, due to akonadi's async nature. * So we make the check inside the editor, and add new categories to config. This way * the editor can be used standalone too. * */ void checkForUnknownCategories( const QStringList &categoriesToCheck ); Ui::EventOrTodoDesktop *mUi; Akonadi::Tag::List mSelectedTags; + QStringList mCategoriesToCheck; bool mDirty; }; } #endif