1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwSongdbSongBooksEditWidget.cpp
22 * @brief Widget for editing song books.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwSongdbSongBooksEditWidget.h"
27 #include "KwSongdbSongBookItem.h"
41 /// Show the edit song books dialog.
42 KwSongdbSongBooksEditWidget
* KwSongdbSongBooksEditWidget::showDialog()
44 static QPointer
<KDialog
> dialog
;
45 static QPointer
<KwSongdbSongBooksEditWidget
> view
;
49 dialog
= new KDialog();
50 view
= new KwSongdbSongBooksEditWidget();
51 dialog
->setMainWidget(view
);
52 dialog
->setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
53 dialog
->enableButtonApply(false);
55 connect(dialog
, SIGNAL(applyClicked()),
57 connect(dialog
, SIGNAL(okClicked()),
59 connect(view
, SIGNAL(changed(bool)),
60 dialog
, SLOT(enableButtonApply(bool)));
62 dialog
->setWindowTitle(i18n("Edit Song Books"));
63 dialog
->setAttribute(Qt::WA_DeleteOnClose
, true);
68 dialog
->activateWindow();
77 * Constructors + destructor
80 /// Default constructor.
81 KwSongdbSongBooksEditWidget::KwSongdbSongBooksEditWidget()
83 , Ui::KwSongdbSongBooksEditWidget_base()
88 QToolBar
* songBooksToolBar
= new QToolBar("songBooksToolBar");
89 layoutSongBooksToolBar
->layout()->addWidget(songBooksToolBar
);
91 KAction
* addAction
= new KAction(KIcon("list-add"), i18n("Add Song Book"), songBooksToolBar
);
92 connect(addAction
, SIGNAL(triggered(bool)),
93 this, SLOT(addSongBook()));
94 songBooksToolBar
->addAction(addAction
);
96 KAction
* removeAction
= new KAction(KIcon("list-remove"), i18n("Remove Song Book"), songBooksToolBar
);
97 connect(removeAction
, SIGNAL(triggered(bool)),
98 this, SLOT(removeSongBook()));
99 songBooksToolBar
->addAction(removeAction
);
103 connect(listSongBooks
, SIGNAL(currentItemChanged(QListWidgetItem
*, QListWidgetItem
*)),
104 this, SLOT(songBookChanged(QListWidgetItem
*, QListWidgetItem
*)));
105 connect(editDescription
, SIGNAL(textChanged()),
106 this, SLOT(descriptionChanged()));
108 QList
<KwSongdbSongBook
*> songBooks
= KwSongdb::self()->songBooks();
109 foreach (KwSongdbSongBook
* songBook
, songBooks
)
111 KwSongdbSongBookItem
* item
= new KwSongdbSongBookItem(songBook
, listSongBooks
);
117 KwSongdbSongBooksEditWidget::~KwSongdbSongBooksEditWidget()
125 /// Save to database.
126 void KwSongdbSongBooksEditWidget::save()
129 for (int i
= 0; i
< listSongBooks
->count(); ++i
)
131 KwSongdbSongBookItem
* item
= dynamic_cast<KwSongdbSongBookItem
*>(listSongBooks
->item(i
));
139 void KwSongdbSongBooksEditWidget::addSongBook()
141 KwSongdbSongBookItem
* item
= new KwSongdbSongBookItem(listSongBooks
);
142 listSongBooks
->setCurrentItem(item
);
149 /// A different song book has been selected.
150 void KwSongdbSongBooksEditWidget::songBookChanged(QListWidgetItem
* current
, QListWidgetItem
* previous
)
152 KwSongdbSongBookItem
* previousVersion
= dynamic_cast<KwSongdbSongBookItem
*>(previous
);
153 KwSongdbSongBookItem
* currentVersion
= dynamic_cast<KwSongdbSongBookItem
*>(current
);
155 if (0 != previousVersion
)
157 disconnect(editAbreviation
, SIGNAL(textEdited(const QString
&)),
158 previousVersion
, SLOT(setAbreviation(const QString
&)));
159 disconnect(editName
, SIGNAL(textEdited(const QString
&)),
160 previousVersion
, SLOT(setName(const QString
&)));
161 disconnect(this, SIGNAL(descriptionChangedSignal(const QString
&)),
162 previousVersion
, SLOT(setDescription(const QString
&)));
165 if (0 != currentVersion
)
167 editAbreviation
->setText(currentVersion
->abreviation());
168 editName
->setText(currentVersion
->name());
169 editDescription
->document()->setPlainText(currentVersion
->description());
171 connect(editAbreviation
, SIGNAL(textEdited(const QString
&)),
172 currentVersion
, SLOT(setAbreviation(const QString
&)));
173 connect(editName
, SIGNAL(textEdited(const QString
&)),
174 currentVersion
, SLOT(setName(const QString
&)));
175 connect(this, SIGNAL(descriptionChangedSignal(const QString
&)),
176 currentVersion
, SLOT(setDescription(const QString
&)));
178 groupSongBook
->setEnabled(0 != currentVersion
);
181 /// Description edit box has been modified.
182 void KwSongdbSongBooksEditWidget::descriptionChanged()
184 descriptionChangedSignal(editDescription
->document()->toPlainText());
187 /// Remove the selected song book.
188 void KwSongdbSongBooksEditWidget::removeSongBook()