ShoppingListDialog::ShoppingListDialog( QWidget *parent, RecipeDB *db ) : QWidget( parent ) { // Store pointer to database database = db; // Design dialog layout = new QGridLayout( this ); layout->cellRect( 2, 2 ); m_sourceListWidget = new KreRecipesListWidget( this, database ); m_sourceListWidget->setListTitle( i18nc( "@title", "Full recipe list" ) ); layout->addWidget( m_sourceListWidget, 0, 0 ); QVBoxLayout* vboxl = new QVBoxLayout(); vboxl->addStretch(); addRecipeButton = new KPushButton( this ); addRecipeButton->setIcon( KIcon( "arrow-right" ) ); vboxl->addWidget( addRecipeButton ); removeRecipeButton = new KPushButton( this ); removeRecipeButton->setIcon( KIcon( "arrow-left" ) ); vboxl->addWidget( removeRecipeButton ); vboxl->addStretch(); layout->addLayout( vboxl, 0, 1 ); m_destListwidget = new KreSearchResultListWidget( this, database ); m_destListwidget->setListTitle( i18nc("@title", "Shopping List") ); layout->addWidget( m_destListwidget, 0, 2 ); buttonBar = new KHBox( this ); layout->addWidget( buttonBar, 1, 1, 1, 2, 0 ); layout->setColumnStretch( 0, 1 ); layout->setColumnStretch( 1, 0 ); layout->setColumnStretch( 2, 1 ); okButton = new KPushButton( buttonBar ); okButton->setObjectName( "okButton" ); okButton->setText( i18nc( "@action:button", "&OK" ) ); okButton->setIcon( KIcon( "dialog-ok" ) ); //buttonBar->layout()->addItem( new QSpacerItem( 10,10, QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) ); clearButton = new KPushButton( buttonBar ); clearButton->setObjectName( "clearButton" ); clearButton->setText( i18nc( "@action:button Clear list", "Clear" ) ); clearButton->setIcon( KIcon( "edit-clear" ) ); // Connect signals & slots connect( addRecipeButton, SIGNAL( clicked() ), this, SLOT( addRecipe() ) ); connect( removeRecipeButton, SIGNAL( clicked() ), this, SLOT( removeRecipe() ) ); connect( okButton, SIGNAL( clicked() ), this, SLOT( showShoppingList() ) ); connect( clearButton, SIGNAL( clicked() ), this, SLOT( clear() ) ); }
category_t *sortRecipe(category_t *category, int size) { int i; recipe_t *current = category->head, *temp = current; if(size < 1) return category; for(i = 0; i < size; i++) { if(strcmp(current->title, temp->title) > 0) temp = current; if(current->next != NULL) current = current->next; } if(strcmp(current->title, temp->title) > 0) temp = current; if(strcmp(temp->title, current->title) != 0) { temp = removeRecipe(category, temp->title); addRecipe(current, temp); } return sortRecipe(category, size-1); }