From kde-commits Fri Apr 08 12:47:47 2016 From: =?utf-8?q?Jos=C3=A9_Manuel_Santamar=C3=ADa_Lema?= Date: Fri, 08 Apr 2016 12:47:47 +0000 To: kde-commits Subject: [krecipes] src: Remove obsolete actions handlers. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=146011968802252 Git commit ba6d0a00eec97f4a1745b646295da23773aa48ad by Jos=C3=A9 Manuel San= tamar=C3=ADa Lema. Committed on 08/04/2016 at 12:22. Pushed by joselema into branch 'master'. Remove obsolete actions handlers. M +0 -6 src/CMakeLists.txt D +0 -221 src/actionshandlers/categoryactionshandler.cpp D +0 -54 src/actionshandlers/categoryactionshandler.h D +0 -118 src/actionshandlers/headeractionshandler.cpp D +0 -41 src/actionshandlers/headeractionshandler.h D +0 -116 src/actionshandlers/ingredientactionshandler.cpp D +0 -40 src/actionshandlers/ingredientactionshandler.h D +0 -116 src/actionshandlers/prepmethodactionshandler.cpp D +0 -39 src/actionshandlers/prepmethodactionshandler.h D +0 -106 src/actionshandlers/propertyactionshandler.cpp D +0 -39 src/actionshandlers/propertyactionshandler.h D +0 -219 src/actionshandlers/unitactionshandler.cpp D +0 -47 src/actionshandlers/unitactionshandler.h M +0 -1 src/dialogs/unitsdialog.cpp M +0 -1 src/dialogs/unitsdialog.h http://commits.kde.org/krecipes/ba6d0a00eec97f4a1745b646295da23773aa48ad diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b133f0a..02ddfd8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,12 +78,6 @@ set(krecipesactionshandlers_SRCS = #FIXME: The classes below are deprecated and must be removed sooner or = later. actionshandlers/actionshandlerbase.cpp - actionshandlers/categoryactionshandler.cpp - actionshandlers/unitactionshandler.cpp - actionshandlers/propertyactionshandler.cpp - actionshandlers/prepmethodactionshandler.cpp - actionshandlers/ingredientactionshandler.cpp - actionshandlers/headeractionshandler.cpp actionshandlers/recipeactionshandler.cpp ) = diff --git a/src/actionshandlers/categoryactionshandler.cpp b/src/actionsha= ndlers/categoryactionshandler.cpp deleted file mode 100644 index e660b2a..0000000 --- a/src/actionshandlers/categoryactionshandler.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "categoryactionshandler.h" - -#include -#include -#include -#include -#include -#include -#include -class Q3ListViewItem; - -#include "datablocks/elementlist.h" - -#include "backends/recipedb.h" - -#include "widgets/categorylistview.h" - -#include "dialogs/createcategorydialog.h" -#include "dialogs/dependanciesdialog.h" - - -CategoryActionsHandler::CategoryActionsHandler( StdCategoryListView *_pare= ntListView, RecipeDB *db ): - ActionsHandlerBase( _parentListView, db ), - clipboard_item( 0 ), - pasteAction( 0 ), - pasteAsSubAction( 0 ) -{ - connect( kpop, SIGNAL( aboutToShow() ), SLOT( preparePopup() ) ); - connect( parentListView, - SIGNAL( moved( Q3ListViewItem *, Q3ListViewItem *, Q3ListViewItem * ) ), - SLOT( changeCategoryParent( Q3ListViewItem *, Q3ListViewItem *, Q3ListVi= ewItem * ) ) - ); -} - -void CategoryActionsHandler::setCategoryPasteAction( KAction * action ) -{ - kpop->addAction( action ); - pasteAction =3D action; -} - -void CategoryActionsHandler::setPasteAsSubcategoryAction( KAction * action= ) -{ - kpop->addAction( action ); - pasteAsSubAction =3D action; -} - -void CategoryActionsHandler::createNew() -{ - ElementList categories; - database->loadCategories( &categories ); - QPointer categoryDialog =3D new CreateCategoryDialo= g( parentListView, categories ); - - if ( categoryDialog->exec() =3D=3D QDialog::Accepted ) { - QString result =3D categoryDialog->newCategoryName(); - int subcategory =3D categoryDialog->subcategory(); - - //check bounds first - if ( checkBounds( result ) ) - database->createNewCategory( result, subcategory ); // Create the new c= ategory in the database - } - delete categoryDialog; -} - -void CategoryActionsHandler::cut() -{ - //restore a never used cut - if ( clipboard_item ) { - if ( clipboard_parent ) - clipboard_parent->insertItem( clipboard_item ); - else - parentListView->insertItem( clipboard_item ); - clipboard_item =3D 0; - } - - Q3ListViewItem *item =3D parentListView->currentItem(); - - if ( item ) { - clipboard_item =3D item; - clipboard_parent =3D item->parent(); - - if ( item->parent() ) - item->parent() ->takeItem( item ); - else - parentListView->takeItem( item ); - } -} - -void CategoryActionsHandler::paste() -{ - Q3ListViewItem * item =3D parentListView->currentItem(); - if ( item && clipboard_item ) { - if ( item->parent() ) - item->parent() ->insertItem( clipboard_item ); - else - parentListView->insertItem( clipboard_item ); - - database->modCategory( clipboard_item->text( 1 ).toInt(), item->parent()= ? item->parent() ->text( 1 ).toInt() : -1 ); - clipboard_item =3D 0; - } -} - -void CategoryActionsHandler::pasteAsSub() -{ - Q3ListViewItem * item =3D parentListView->currentItem(); - - if ( item && clipboard_item ) { - item->insertItem( clipboard_item ); - database->modCategory( clipboard_item->text( 1 ).toInt(), item->text( 1 = ).toInt() ); - clipboard_item =3D 0; - } -} - -void CategoryActionsHandler::changeCategoryParent(Q3ListViewItem *item, - Q3ListViewItem * /*afterFirst*/, Q3ListViewItem * /*afterNow*/ ) -{ - int new_parent_id =3D -1; - if ( Q3ListViewItem * parent =3D item->parent() ) - new_parent_id =3D parent->text( 1 ).toInt(); - - int cat_id =3D item->text( 1 ).toInt(); - - database->modCategory( cat_id, new_parent_id, false ); -} - -void CategoryActionsHandler::remove() -{ - Q3ListViewItem * item =3D parentListView->currentItem(); - - if ( item ) { - int id =3D item->text( 1 ).toInt(); - - ElementList recipeDependancies; - database->findUseOfCategoryInRecipes( &recipeDependancies, id ); - - if ( recipeDependancies.isEmpty() ) { - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "Are you sure you want to delete this category and all its subcat= egories?" ) ) ) { - case KMessageBox::Continue: - database->removeCategory( id ); - break; - } - return; - } - else { // need warning! - ListInfo info; - info.list =3D recipeDependancies; - info.name =3D i18n("Recipes"); - QPointer warnDialog =3D new DependanciesDialog( par= entListView, info, false ); - - if ( warnDialog->exec() =3D=3D QDialog::Accepted ) - database->removeCategory( id ); - - delete warnDialog; - } - } -} - -bool CategoryActionsHandler::checkBounds( const QString &name ) -{ - if ( name.length() > int(database->maxCategoryNameLength()) ) { - KMessageBox::error( parentListView, - i18np( "Category name cannot be longer than 1 character.", - "Category name cannot be longer than %1 characters." , - database->maxCategoryNameLength() )); - return false; - } - - return true; -} - -void CategoryActionsHandler::preparePopup() -{ - //only enable the paste actions if clipboard_item isn't null - pasteAction->setEnabled( clipboard_item ); - pasteAsSubAction->setEnabled( clipboard_item ); -} - -void CategoryActionsHandler::saveElement( Q3ListViewItem* i ) -{ - CategoryListItem * cat_it =3D ( CategoryListItem* ) i; - - if ( !checkBounds( cat_it->categoryName() ) ) { - parentListView->reload(ForceReload); //reset the changed text - return ; - } - - int existing_id =3D database->findExistingCategoryByName( cat_it->categor= yName() ); - int cat_id =3D cat_it->categoryId(); - if ( existing_id !=3D -1 && existing_id !=3D cat_id ) //category already= exists with this label... merge the two - { - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "This category already exists. Continuing will merge these two cat= egories into one. Are you sure?" ) ) ) - { - case KMessageBox::Continue: { - database->mergeCategories( existing_id, cat_id ); - break; - } - default: - parentListView->reload(ForceReload); - break; - } - } - else - database->modCategory( cat_id, cat_it->categoryName() ); -} - -CategoryActionsHandler::~CategoryActionsHandler() -{ - delete clipboard_item; -} diff --git a/src/actionshandlers/categoryactionshandler.h b/src/actionshand= lers/categoryactionshandler.h deleted file mode 100644 index 5f0a4f4..0000000 --- a/src/actionshandlers/categoryactionshandler.h +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef CATEGORYACTIONSHANDLER_H -#define CATEGORYACTIONSHANDLER_H - -#include "actionshandlers/actionshandlerbase.h" - -class StdCategoryListView; -class Q3ListViewItem; -class KAction; - -class CategoryActionsHandler : public ActionsHandlerBase -{ - Q_OBJECT - -public: - CategoryActionsHandler( StdCategoryListView *_parentListView, RecipeDB *d= b ); - ~CategoryActionsHandler(); - - void setCategoryPasteAction( KAction * action ); - void setPasteAsSubcategoryAction( KAction * action ); - -public slots: - void createNew(); - void cut(); - void paste(); - void pasteAsSub(); - void changeCategoryParent(Q3ListViewItem *item, - Q3ListViewItem * /*afterFirst*/, Q3ListViewItem * /*afterNow*/ ); - void remove(); - -private: - Q3ListViewItem *clipboard_item; - Q3ListViewItem *clipboard_parent; - KAction *pasteAction; - KAction *pasteAsSubAction; - bool checkBounds( const QString &name ); = - -private slots: - void preparePopup(); - void saveElement( Q3ListViewItem* i ); -}; - -#endif //CATEGORYACTIONSHANDLER_H - diff --git a/src/actionshandlers/headeractionshandler.cpp b/src/actionshand= lers/headeractionshandler.cpp deleted file mode 100644 index 75d7a96..0000000 --- a/src/actionshandlers/headeractionshandler.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Cyril Bosselut = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "headeractionshandler.h" - -#include -#include -#include -#include -#include -class Q3ListViewItem; - -#include "datablocks/elementlist.h" - -#include "backends/recipedb.h" - -#include "widgets/dblistviewbase.h" - -#include "dialogs/createelementdialog.h" -#include "dialogs/dependanciesdialog.h" - - -HeaderActionsHandler::HeaderActionsHandler( DBListViewBase *_parentListVie= w, RecipeDB *db ): - ActionsHandlerBase( _parentListView, db ) -{ -} - -void HeaderActionsHandler::createNew() -{ - QPointer elementDialog =3D new CreateElementDialog( = parentListView, i18n( "New Header" ) ); - - if ( elementDialog->exec() =3D=3D QDialog::Accepted ) { - QString result =3D elementDialog->newElementName(); - - //check bounds first - if ( checkBounds( result ) ) - database->createNewIngGroup( result ); // Create the new header in the = database - } - delete elementDialog; -} - -void HeaderActionsHandler::remove() -{ - Q3ListViewItem * item =3D parentListView->currentItem(); - - if ( item ) { - int id =3D item->text( 1 ).toInt(); - - ElementList dependingRecipes; - database->findUseOfIngGroupInRecipes( &dependingRecipes, id); - - if ( dependingRecipes.isEmpty() ) - database->removeIngredientGroup( id ); - else { // Need Warning! - ListInfo list; - list.list =3D dependingRecipes; - list.name =3D i18n( "Recipes" ); - - QPointer warnDialog =3D new DependanciesDialog( par= entListView, list, false ); - if ( warnDialog->exec() =3D=3D QDialog::Accepted ) - database->removeIngredientGroup( id ); - delete warnDialog; - } - } -} - -bool HeaderActionsHandler::checkBounds( const QString &name ) -{ - if ( name.length() > int(database->maxIngGroupNameLength()) ) { - KMessageBox::error( parentListView, - i18np( "Header cannot be longer than 1 character.", "Header cannot be lo= nger than %1 characters.", - database->maxIngGroupNameLength() ) ); - return false; - } - else if ( name.trimmed().isEmpty() ) - return false; - - return true; - -} - -void HeaderActionsHandler::saveElement( Q3ListViewItem* i ) -{ - if ( !checkBounds( i->text( 0 ) ) ) { - parentListView->reload(ForceReload); //reset the changed text - return ; - } - - int existing_id =3D database->findExistingIngredientGroupByName( i->text(= 0 ) ); - int id =3D i->text( 1 ).toInt(); - if ( existing_id !=3D -1 && existing_id !=3D id ) //already exists with = this label... merge the two - { - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "This header already exists. Continuing will merge these two head= ers into one. Are you sure?" ) ) ) - { - case KMessageBox::Continue: { - database->modIngredientGroup( id, i->text( 0 ) ); - database->mergeIngredientGroups( id, existing_id ); - break; - } - default: - parentListView->reload(ForceReload); - break; - } - } - else { - database->modIngredientGroup( id, i->text( 0 ) ); - } -} diff --git a/src/actionshandlers/headeractionshandler.h b/src/actionshandle= rs/headeractionshandler.h deleted file mode 100644 index b5de9e8..0000000 --- a/src/actionshandlers/headeractionshandler.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Cyril Bosselut = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef HEADERACTIONSHANDLER_H -#define HEADERACTIONSHANDLER_H - -#include "actionshandlers/actionshandlerbase.h" - -class DBListViewBase; -class Q3ListViewItem; - -class HeaderActionsHandler : public ActionsHandlerBase -{ - Q_OBJECT - -public: - HeaderActionsHandler( DBListViewBase *_parentListView, RecipeDB *db ); - ~HeaderActionsHandler() {} - -public slots: - void createNew(); - void remove(); - -private: - bool checkBounds( const QString &name ); - -private slots: - void saveElement( Q3ListViewItem* i ); -}; - -#endif //HEADERACTIONSHANDLER_H - diff --git a/src/actionshandlers/ingredientactionshandler.cpp b/src/actions= handlers/ingredientactionshandler.cpp deleted file mode 100644 index b1673da..0000000 --- a/src/actionshandlers/ingredientactionshandler.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2008 Montel Laurent = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "ingredientactionshandler.h" - -#include -#include -#include -#include -#include -class Q3ListViewItem; - -#include "datablocks/elementlist.h" - -#include "backends/recipedb.h" - -#include "widgets/dblistviewbase.h" - -#include "dialogs/createelementdialog.h" -#include "dialogs/dependanciesdialog.h" - - -IngredientActionsHandler::IngredientActionsHandler( DBListViewBase *_paren= tListView, RecipeDB *db ): - ActionsHandlerBase( _parentListView, db ) -{ -} - -void IngredientActionsHandler::createNew() -{ - QPointer elementDialog =3D new CreateElementDialog( = parentListView, i18n( "New Ingredient" ) ); - - if ( elementDialog->exec() =3D=3D QDialog::Accepted ) { - QString result =3D elementDialog->newElementName(); - - //check bounds first - if ( checkBounds( result ) ) - database->createNewIngredient( result ); // Create the new ingredient i= n the database - } - delete elementDialog; -} - -void IngredientActionsHandler::remove() -{ - Q3ListViewItem * item =3D parentListView->currentItem(); - - if ( item ) { - int id =3D item->text( 1 ).toInt(); - - ElementList dependingRecipes; - database->findIngredientDependancies( id, &dependingRecipes ); - - if ( dependingRecipes.isEmpty() ) - database->removeIngredient( id ); - else { // Need Warning! - ListInfo list; - list.list =3D dependingRecipes; - list.name =3D i18n( "Recipes" ); - - QPointer warnDialog =3D new DependanciesDialog( par= entListView, list ); - warnDialog->setCustomWarning( i18n("You are about to permanently delete= recipes from your database.") ); - if ( warnDialog->exec() =3D=3D QDialog::Accepted ) - database->removeIngredient( id ); - delete warnDialog; - } - } -} - -bool IngredientActionsHandler::checkBounds( const QString &name ) -{ - if ( name.length() > int(database->maxIngredientNameLength()) ) { - KMessageBox::error( parentListView, - i18np( "Ingredient name cannot be longer than 1 character.", - "Ingredient name cannot be longer than %1 characters.", - database->maxIngredientNameLength() ) ); - return false; - } - - return true; - -} - -void IngredientActionsHandler::saveElement( Q3ListViewItem* i ) -{ - if ( !checkBounds( i->text( 0 ) ) ) { - parentListView->reload(ForceReload); //reset the changed text - return ; - } - - int existing_id =3D database->findExistingIngredientByName( i->text( 0 ) = ); - int ing_id =3D i->text( 1 ).toInt(); - if ( existing_id !=3D -1 && existing_id !=3D ing_id ) //ingredient alrea= dy exists with this label... merge the two - { - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "This ingredient already exists. Continuing will merge these two i= ngredients into one. Are you sure?" ) ) ) - { - case KMessageBox::Continue: { - database->mergeIngredients( existing_id, ing_id ); - break; - } - default: - parentListView->reload(ForceReload); - break; - } - } - else { - database->modIngredient( ( i->text( 1 ) ).toInt(), i->text( 0 ) ); - } -} diff --git a/src/actionshandlers/ingredientactionshandler.h b/src/actionsha= ndlers/ingredientactionshandler.h deleted file mode 100644 index 4adb6bf..0000000 --- a/src/actionshandlers/ingredientactionshandler.h +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2008 Montel Laurent = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef INGREDIENTACTIONSHANDLER_H -#define INGREDIENTACTIONSHANDLER_H - -#include "actionshandlers/actionshandlerbase.h" - -class DBListViewBase; -class Q3ListViewItem; - -class IngredientActionsHandler : public ActionsHandlerBase -{ -Q_OBJECT - -public: - IngredientActionsHandler( DBListViewBase *_parentListView, RecipeDB *db ); - ~IngredientActionsHandler() {} - -public slots: - void createNew(); - void remove(); - -private: - bool checkBounds( const QString &name ); - -private slots: - void saveElement( Q3ListViewItem* i ); -}; - -#endif //INGREDIENTACTIONSHANDLER_H - diff --git a/src/actionshandlers/prepmethodactionshandler.cpp b/src/actions= handlers/prepmethodactionshandler.cpp deleted file mode 100644 index 560cebe..0000000 --- a/src/actionshandlers/prepmethodactionshandler.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "prepmethodactionshandler.h" - -#include -#include -#include -#include -#include -#include -class Q3ListViewItem; - -#include "datablocks/elementlist.h" - -#include "backends/recipedb.h" - -#include "widgets/dblistviewbase.h" - -#include "dialogs/createelementdialog.h" -#include "dialogs/dependanciesdialog.h" - - -PrepMethodActionsHandler::PrepMethodActionsHandler( DBListViewBase *_paren= tListView, RecipeDB *db ): - ActionsHandlerBase( _parentListView, db ) -{ -} - -void PrepMethodActionsHandler::createNew() -{ - QPointer elementDialog =3D new CreateElementDialog( = parentListView, i18n( "New Preparation Method" ) ); - - if ( elementDialog->exec() =3D=3D QDialog::Accepted ) { - QString result =3D elementDialog->newElementName(); - - //check bounds first - if ( checkBounds( result ) ) - database->createNewPrepMethod( result ); // Create the new prepMethod i= n the database - } - - delete elementDialog; -} - -void PrepMethodActionsHandler::remove() -{ - Q3ListViewItem * item =3D parentListView->currentItem(); - - if ( item ) { - ElementList dependingRecipes; - int prepMethodID =3D item->text( 1 ).toInt(); - database->findPrepMethodDependancies( prepMethodID, &dependingRecipes ); - if ( dependingRecipes.isEmpty() ) - database->removePrepMethod( prepMethodID ); - else // Need Warning! - { - ListInfo info; - info.list =3D dependingRecipes; - info.name =3D i18n("Recipes"); - QPointer warnDialog =3D new DependanciesDialog( par= entListView, info ); - warnDialog->setCustomWarning( i18n("You are about to permanently delete= recipes from your database.") ); - if ( warnDialog->exec() =3D=3D QDialog::Accepted ) - database->removePrepMethod( prepMethodID ); - delete warnDialog; - } - } -} - -bool PrepMethodActionsHandler::checkBounds( const QString &name ) -{ - if ( name.length() > int(database->maxPrepMethodNameLength()) ) { - KMessageBox::error( parentListView, - i18np( "Preparation method cannot be longer than 1 character.", - "Preparation method cannot be longer than %1 characters." , - database->maxPrepMethodNameLength() ) ); - return false; - } - - return true; - -} - -void PrepMethodActionsHandler::saveElement( Q3ListViewItem* i ) -{ - if ( !checkBounds( i->text( 0 ) ) ) { - parentListView->reload(ForceReload); //reset the changed text - return ; - } - - int existing_id =3D database->findExistingIngredientGroupByName( i->text(= 0 ) ); - int id =3D i->text( 1 ).toInt(); - if ( existing_id !=3D -1 && existing_id !=3D id ) //already exists with = this label... merge the two - { - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "This header already exists. Continuing will merge these two head= ers into one. Are you sure?" ) ) ) - { - case KMessageBox::Continue: { - database->modIngredientGroup( id, i->text( 0 ) ); - database->mergeIngredientGroups( id, existing_id ); - break; - } - default: - parentListView->reload(ForceReload); - break; - } - } - else { - database->modIngredientGroup( id, i->text( 0 ) ); - } -} diff --git a/src/actionshandlers/prepmethodactionshandler.h b/src/actionsha= ndlers/prepmethodactionshandler.h deleted file mode 100644 index 5afc133..0000000 --- a/src/actionshandlers/prepmethodactionshandler.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef PREPMETHODACTIONSHANDLER_H -#define PREPMETHODACTIONSHANDLER_H - -#include "actionshandlers/actionshandlerbase.h" - -class DBListViewBase; -class Q3ListViewItem; - -class PrepMethodActionsHandler : public ActionsHandlerBase -{ - Q_OBJECT - -public: - PrepMethodActionsHandler( DBListViewBase *_parentListView, RecipeDB *db ); - ~PrepMethodActionsHandler() {} - -public slots: - void createNew(); - void remove(); - -private: - bool checkBounds( const QString &name ); - -private slots: - void saveElement( Q3ListViewItem* i ); -}; - -#endif //PREPMETHODACTIONSHANDLER_H - diff --git a/src/actionshandlers/propertyactionshandler.cpp b/src/actionsha= ndlers/propertyactionshandler.cpp deleted file mode 100644 index 64dfaf2..0000000 --- a/src/actionshandlers/propertyactionshandler.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "propertyactionshandler.h" - -#include -#include -#include -#include -#include -class Q3ListViewItem; - -#include "datablocks/elementlist.h" - -#include "backends/recipedb.h" - -#include "widgets/dblistviewbase.h" - -#include "dialogs/createpropertydialog.h" -#include "dialogs/dependanciesdialog.h" - - -PropertyActionsHandler::PropertyActionsHandler( DBListViewBase *_parentLis= tView, RecipeDB *db ): - ActionsHandlerBase( _parentListView, db ) -{ -} - -void PropertyActionsHandler::createNew() -{ - UnitList list; - database->loadUnits( &list ); - QPointer propertyDialog =3D new CreatePropertyDialo= g( parentListView, &list ); - - if ( propertyDialog->exec() =3D=3D QDialog::Accepted ) { - QString name =3D propertyDialog->newPropertyName(); - QString units =3D propertyDialog->newUnitsName(); - if ( !( ( name.isEmpty() ) || ( units.isEmpty() ) ) ) // Make sure none= of the fields are empty - { - //check bounds first - if ( checkBounds( name ) ) - database->addProperty( name, units ); - } - } - delete propertyDialog; -} - -void PropertyActionsHandler::remove() -{ - Q3ListViewItem * item =3D parentListView->currentItem(); - - if ( item ) { - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "Are you sure you want to delete this property?" ) ) ) { - case KMessageBox::Continue: - database->removeProperty( item->text( 2 ).toInt() ); - break; - default: - break; - } - } -} - -bool PropertyActionsHandler::checkBounds( const QString &name ) -{ - if ( name.length() > (int)database->maxPropertyNameLength() ) { - KMessageBox::error( parentListView, - i18np( "Property name cannot be longer than 1 character.", - "Property name cannot be longer than %1 characters." , - database->maxPropertyNameLength() ) ); - return false; - } - return true; -} - -void PropertyActionsHandler::saveElement( Q3ListViewItem* i ) -{ - if ( !checkBounds( i->text( 0 ) ) ) { - parentListView->reload(); //reset the changed text - return ; - } - int existing_id =3D database->findExistingPropertyByName( i->text( 0 ) ); - int prop_id =3D i->text( 2 ).toInt(); - if ( existing_id !=3D -1 && existing_id !=3D prop_id ) //already exists = with this label... merge the two - { - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "This property already exists. Continuing will merge these two pr= operties into one. Are you sure?" ) ) ) - { - case KMessageBox::Continue: { - database->mergeProperties( existing_id, prop_id ); - break; - } - default: - parentListView->reload(); - break; - } - } - else - database->modProperty( prop_id, i->text( 0 ) ); -} diff --git a/src/actionshandlers/propertyactionshandler.h b/src/actionshand= lers/propertyactionshandler.h deleted file mode 100644 index e24c6c9..0000000 --- a/src/actionshandlers/propertyactionshandler.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004 Jason Kivlighn = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef PROPERTYACTIONSHANDLER_H -#define PROPERTYACTIONSHANDLER_H - -#include "actionshandlers/actionshandlerbase.h" - -class DBListViewBase; -class Q3ListViewItem; - -class PropertyActionsHandler : public ActionsHandlerBase -{ - Q_OBJECT - -public: - PropertyActionsHandler( DBListViewBase *_parentListView, RecipeDB *db ); - ~PropertyActionsHandler() {} - -public slots: - void createNew(); - void remove(); - -private: - bool checkBounds( const QString &name ); - -private slots: - void saveElement( Q3ListViewItem* i ); -}; - -#endif //PROPERTYACTIONSHANDLER_H - diff --git a/src/actionshandlers/unitactionshandler.cpp b/src/actionshandle= rs/unitactionshandler.cpp deleted file mode 100644 index 77a26fa..0000000 --- a/src/actionshandlers/unitactionshandler.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004-2006 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Cyril Bosselut = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#include "unitactionshandler.h" - -#include -#include -#include -#include -#include -#include -#include -class Q3ListViewItem; - -#include "datablocks/elementlist.h" - -#include "backends/recipedb.h" - -#include "widgets/unitlistview.h" - -#include "dialogs/createunitdialog.h" -#include "dialogs/dependanciesdialog.h" - - -UnitActionsHandler::UnitActionsHandler( StdUnitListView *_parentListView, = RecipeDB *db ): - ActionsHandlerBase( _parentListView, db ) -{ - connect( parentListView, - SIGNAL( itemRenamed( Q3ListViewItem*, const QString &, int ) ), - SLOT( saveUnit( Q3ListViewItem*, const QString &, int ) ) - ); -} - -void UnitActionsHandler::createNew() -{ - QPointer unitDialog =3D new CreateUnitDialog( parentLis= tView ); - - if ( unitDialog->exec() =3D=3D QDialog::Accepted ) { - Unit result =3D unitDialog->newUnit(); - - //check bounds first - if ( checkBounds( result ) - && database->findExistingUnitByName( result.name() ) =3D=3D -1 - && database->findExistingUnitByName( result.plural() ) =3D=3D -1 - ) { - database->createNewUnit( result ); - } - } - delete unitDialog; -} - -void UnitActionsHandler::rename() -{ - UnitListViewItem * item =3D (UnitListViewItem*)parentListView->currentIte= m(); - - if ( item ) { - QPointer unitDialog =3D new CreateUnitDialog( = - parentListView, item->text(0), item->text(2), item->text(1), item->text= (3), - item->type(), false ); - unitDialog->setCaption( i18n("Rename Unit") ); - - if ( unitDialog->exec() =3D=3D QDialog::Accepted ) { - UnitListViewItem *unit_item =3D (UnitListViewItem*)item; - Unit origUnit =3D unit_item->unit(); - Unit newUnit =3D unitDialog->newUnit(); - - //for each changed entry, save the change individually - - Unit unit =3D origUnit; - - if ( newUnit.name() !=3D origUnit.name() ) { - unit.setName(newUnit.name()); - unit_item->setUnit( unit ); - saveUnit( unit_item, newUnit.name(), 0 ); - - //saveUnit will call database->modUnit which deletes the list item we = were using - unit_item =3D (UnitListViewItem*) parentListView->findItem( QString::n= umber(unit.id()), 5 ); - } - - if ( newUnit.plural() !=3D origUnit.plural() ) { - unit.setPlural(newUnit.plural()); - unit_item->setUnit( unit ); - saveUnit( unit_item, newUnit.plural(), 2 ); - unit_item =3D (UnitListViewItem*) parentListView->findItem( QString::n= umber(unit.id()), 5 ); - } - - if ( !newUnit.nameAbbrev().trimmed().isEmpty() && newUnit.nameAbbrev() = !=3D origUnit.nameAbbrev() ) { - unit.setNameAbbrev(newUnit.nameAbbrev()); - unit_item->setUnit( unit ); - saveUnit( unit_item, newUnit.nameAbbrev(), 1 ); - unit_item =3D (UnitListViewItem*) parentListView->findItem( QString::n= umber(unit.id()), 5 ); - } - if ( !newUnit.pluralAbbrev().trimmed().isEmpty() && newUnit.pluralAbbre= v() !=3D origUnit.pluralAbbrev() ) { - unit.setPluralAbbrev(newUnit.pluralAbbrev()); - unit_item->setUnit( unit ); - saveUnit( unit_item, newUnit.pluralAbbrev(), 3 ); - unit_item =3D (UnitListViewItem*) parentListView->findItem( QString::n= umber(unit.id()), 5 ); - } - if ( newUnit.type() !=3D unit.type() ) { - unit.setType(newUnit.type()); - unit_item->setUnit( unit ); - saveUnit( unit_item, unit_item->text(4), 5 ); - } - } - delete unitDialog; - } -} - -void UnitActionsHandler::remove() -{ - // Find selected unit item - UnitListViewItem* it =3D (UnitListViewItem*) parentListView->currentItem(= ); - - if ( it ) { - int unitID =3D it->unit().id(); - - ElementList recipeDependancies, propertyDependancies, weightDependancies; - database->findUnitDependancies( unitID, &propertyDependancies, &recipeDe= pendancies, &weightDependancies ); - - QList lists; - if ( !recipeDependancies.isEmpty() ) { - ListInfo info; - info.list =3D recipeDependancies; - info.name =3D i18n("Recipes"); - lists << info; - } - if ( !propertyDependancies.isEmpty() ) { - ListInfo info; - info.list =3D propertyDependancies; - info.name =3D i18n("Properties"); - lists << info; - } - if ( !weightDependancies.isEmpty() ) { - ListInfo info; - info.list =3D weightDependancies; - info.name =3D i18n("Ingredient Weights"); - lists << info; - } - - if ( lists.isEmpty() ) - database->removeUnit( unitID ); - else { // need warning! - QPointer warnDialog =3D new DependanciesDialog( par= entListView, lists ); - if ( !recipeDependancies.isEmpty() ) - warnDialog->setCustomWarning( i18n("You are about to permanently delet= e recipes from your database.") ); - if ( warnDialog->exec() =3D=3D QDialog::Accepted ) - database->removeUnit( unitID ); - delete warnDialog; - } - } -} - -bool UnitActionsHandler::checkBounds( const Unit &unit ) -{ - if ( unit.name().length() > int(database->maxUnitNameLength()) || - unit.plural().length() > int(database->maxUnitNameLength()) ) { - KMessageBox::error( parentListView, - i18np( "Unit name cannot be longer than 1 character.", - "Unit name cannot be longer than %1 characters.", - database->maxUnitNameLength() ) ); - return false; - } - else if ( unit.name().trimmed().isEmpty() || unit.plural().trimmed().isEm= pty() ) - return false; - - return true; -} - -void UnitActionsHandler::renameElement( Q3ListViewItem* i, const QPoint & = /*p*/, int c ) -{ - if ( i ) { - if ( c !=3D 4 ) - parentListView->rename( i, c ); - else { - ((StdUnitListView*)parentListView)->insertTypeComboBox(i); - } - } -} - -void UnitActionsHandler::saveUnit( Q3ListViewItem* i, const QString &text,= int c ) -{ - //skip abbreviations - if ( c =3D=3D 0 || c =3D=3D 2 ) { - if ( !checkBounds( Unit( text, text ) ) ) { - parentListView->reload(ForceReload); //reset the changed text - return ; - } - } - - int existing_id =3D database->findExistingUnitByName( text ); - - UnitListViewItem *unit_it =3D (UnitListViewItem*)i; - int unit_id =3D unit_it->unit().id(); - if ( existing_id !=3D -1 && existing_id !=3D unit_id && !text.trimmed().i= sEmpty() ) { //unit already exists with this label... merge the two - switch ( KMessageBox::warningContinueCancel( parentListView, - i18n( "This unit already exists. Continuing will merge these two units = into one. Are you sure?" ) ) ) { - case KMessageBox::Continue: { - database->modUnit( unit_it->unit() ); - database->mergeUnits( unit_id, existing_id ); - break; - } - default: - parentListView->reload(ForceReload); - break; - } - } - else { - database->modUnit( unit_it->unit() ); - } -} diff --git a/src/actionshandlers/unitactionshandler.h b/src/actionshandlers= /unitactionshandler.h deleted file mode 100644 index 89b528e..0000000 --- a/src/actionshandlers/unitactionshandler.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************= ** -* Copyright =C2=A9 2004-2006 Jason Kivlighn = * -* Copyright =C2=A9 2004 Unai Garro = * -* Copyright =C2=A9 2004 Cyril Bosselut = * -* Copyright =C2=A9 2009 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * -* * -* 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; either version 2 of the License, or * -* (at your option) any later version. * -**************************************************************************= */ - -#ifndef UNITACTIONSHANDLER_H -#define UNITACTIONSHANDLER_H - -#include "actionshandlers/actionshandlerbase.h" - -class StdUnitListView; -class Q3ListViewItem; -class Unit; -class QPoint; -class QString; - -class UnitActionsHandler : public ActionsHandlerBase -{ - Q_OBJECT - -public: - UnitActionsHandler( StdUnitListView *_parentListView, RecipeDB *db ); - ~UnitActionsHandler() {} - -public slots: - void createNew(); - void rename(); - void remove(); - -private: - bool checkBounds( const Unit &unit ); - -private slots: - void renameElement( Q3ListViewItem* i, const QPoint &p, int c ); - void saveElement( Q3ListViewItem* ){} - void saveUnit( Q3ListViewItem* i, const QString &text, int c ); -}; - -#endif //UNITACTIONSHANDLER_H - diff --git a/src/dialogs/unitsdialog.cpp b/src/dialogs/unitsdialog.cpp index 022e22e..6a7a298 100644 --- a/src/dialogs/unitsdialog.cpp +++ b/src/dialogs/unitsdialog.cpp @@ -22,7 +22,6 @@ #include "widgets/kreconversiontable.h" #include "widgets/unitlistview.h" //TODO: Remove, deprecated. #include "widgets/kreunitlistwidget.h" //TODO: Remove, deprecated. -#include "actionshandlers/unitactionshandler.h" //TODO: Remove, deprecated. #include "actionshandlers/kreunitactionshandler.h" = #include diff --git a/src/dialogs/unitsdialog.h b/src/dialogs/unitsdialog.h index d19d59e..abefefa 100644 --- a/src/dialogs/unitsdialog.h +++ b/src/dialogs/unitsdialog.h @@ -21,7 +21,6 @@ class RecipeDB; class KreConversionTable; class KreUnitListWidget; -class UnitActionsHandler; //TODO: Remove, obsolete. class KreUnitActionsHandler; class KAction; class KPushButton;