Added playlist actions (insert, delete, move up, move down), with only insert working...
[kworship.git] / kworship / songdb / KwSongdbSongBooksEditWidget.cpp
blob3d57defcfcd965442660069d39f3023fa34012fd
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 /**
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"
28 #include "KwSongdb.h"
30 #include <KAction>
31 #include <KDialog>
32 #include <KLocale>
34 #include <QToolBar>
35 #include <QPointer>
38 * Static
41 /// Show the edit song books dialog.
42 KwSongdbSongBooksEditWidget* KwSongdbSongBooksEditWidget::showDialog()
44 static QPointer<KDialog> dialog;
45 static QPointer<KwSongdbSongBooksEditWidget> view;
47 if (0 == dialog)
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()),
56 view, SLOT(save()));
57 connect(dialog, SIGNAL(okClicked()),
58 view, SLOT(save()));
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);
64 dialog->show();
66 else
68 dialog->activateWindow();
69 dialog->raise();
73 return view;
77 * Constructors + destructor
80 /// Default constructor.
81 KwSongdbSongBooksEditWidget::KwSongdbSongBooksEditWidget()
82 : QWidget()
83 , Ui::KwSongdbSongBooksEditWidget_base()
85 setupUi(this);
87 // Song books toolbar
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);
102 // Signals
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);
115 /// Destructor.
116 KwSongdbSongBooksEditWidget::~KwSongdbSongBooksEditWidget()
121 * Saving and loading
124 /// Save to database.
125 void KwSongdbSongBooksEditWidget::save()
127 // Song books
128 for (int i = 0; i < listSongBooks->count(); ++i)
130 KwSongdbSongBookItem* item = dynamic_cast<KwSongdbSongBookItem*>(listSongBooks->item(i));
131 Q_ASSERT(0 != item);
132 item->save();
134 saved();
137 /// Add a song book.
138 void KwSongdbSongBooksEditWidget::addSongBook()
140 KwSongdbSongBookItem* item = new KwSongdbSongBookItem(listSongBooks);
141 listSongBooks->setCurrentItem(item);
145 * Private slots
148 /// A different song book has been selected.
149 void KwSongdbSongBooksEditWidget::songBookChanged(QListWidgetItem* current, QListWidgetItem* previous)
151 KwSongdbSongBookItem* previousVersion = dynamic_cast<KwSongdbSongBookItem*>(previous);
152 KwSongdbSongBookItem* currentVersion = dynamic_cast<KwSongdbSongBookItem*>(current);
154 if (0 != previousVersion)
156 disconnect(editAbreviation, SIGNAL(textEdited(const QString&)),
157 previousVersion, SLOT(setAbreviation(const QString&)));
158 disconnect(editName, SIGNAL(textEdited(const QString&)),
159 previousVersion, SLOT(setName(const QString&)));
160 disconnect(this, SIGNAL(descriptionChangedSignal(const QString&)),
161 previousVersion, SLOT(setDescription(const QString&)));
164 if (0 != currentVersion)
166 editAbreviation->setText(currentVersion->abreviation());
167 editName->setText(currentVersion->name());
168 editDescription->document()->setPlainText(currentVersion->description());
170 connect(editAbreviation, SIGNAL(textEdited(const QString&)),
171 currentVersion, SLOT(setAbreviation(const QString&)));
172 connect(editName, SIGNAL(textEdited(const QString&)),
173 currentVersion, SLOT(setName(const QString&)));
174 connect(this, SIGNAL(descriptionChangedSignal(const QString&)),
175 currentVersion, SLOT(setDescription(const QString&)));
177 groupSongBook->setEnabled(0 != currentVersion);
180 /// Description edit box has been modified.
181 void KwSongdbSongBooksEditWidget::descriptionChanged()
183 descriptionChangedSignal(editDescription->document()->toPlainText());
186 /// Remove the selected song book.
187 void KwSongdbSongBooksEditWidget::removeSongBook()