Warning, file /multimedia/juk/tagguesserconfigdlg.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /**
0002  * Copyright (C) 2003 Frerich Raabe <raabe@kde.org>
0003  *
0004  * This program is free software; you can redistribute it and/or modify it under
0005  * the terms of the GNU General Public License as published by the Free Software
0006  * Foundation; either version 2 of the License, or (at your option) any later
0007  * version.
0008  *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
0012  *
0013  * You should have received a copy of the GNU General Public License along with
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.
0015  */
0016 
0017 #include "tagguesserconfigdlg.h"
0018 #include "tagguesser.h"
0019 
0020 #include <KLocalizedString>
0021 #include <klineedit.h>
0022 
0023 #include <QStringListModel>
0024 #include <QVBoxLayout>
0025 #include <QPushButton>
0026 #include <QDialogButtonBox>
0027 
0028 #include "iconsupport.h"
0029 
0030 TagGuesserConfigDlg::TagGuesserConfigDlg(QWidget *parent, const char *name)
0031   : QDialog(parent)
0032   , m_child(new TagGuesserConfigDlgWidget(this))
0033   , m_tagSchemeModel(new QStringListModel(TagGuesser::schemeStrings(), m_child->lvSchemes))
0034 {
0035     using namespace IconSupport; // ""_icon
0036 
0037     setObjectName(QLatin1String(name));
0038     setModal(true);
0039     setWindowTitle(i18n("Tag Guesser Configuration"));
0040 
0041     auto vboxLayout = new QVBoxLayout(this);
0042     vboxLayout->addWidget(m_child);
0043 
0044     m_child->bMoveUp->setIcon("arrow-up"_icon);
0045     m_child->bMoveDown->setIcon("arrow-down"_icon);
0046 
0047     m_child->lvSchemes->setModel(m_tagSchemeModel);
0048     m_child->lvSchemes->setHeaderHidden(true);
0049 
0050     connect(m_child->lvSchemes, SIGNAL(clicked(QModelIndex)), this, SLOT(slotCurrentChanged(QModelIndex)));
0051     connect(m_child->bMoveUp, SIGNAL(clicked()), this, SLOT(slotMoveUpClicked()));
0052     connect(m_child->bMoveDown, SIGNAL(clicked()), this, SLOT(slotMoveDownClicked()));
0053     connect(m_child->bAdd, SIGNAL(clicked()), this, SLOT(slotAddClicked()));
0054     connect(m_child->bModify, SIGNAL(clicked()), this, SLOT(slotModifyClicked()));
0055     connect(m_child->bRemove, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));
0056     connect(m_child->dlgButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0057     connect(m_child->dlgButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0058 
0059     resize( 400, 300 );
0060 }
0061 
0062 void TagGuesserConfigDlg::slotCurrentChanged(QModelIndex item)
0063 {
0064     m_child->bRemove->setEnabled(m_tagSchemeModel->rowCount() != 0);
0065 
0066     // Ensure up/down buttons are appropriately enabled.
0067 
0068     if (!m_tagSchemeModel->rowCount() || item == m_tagSchemeModel->index(0, 0, QModelIndex()))
0069         m_child->bMoveUp->setEnabled(false);
0070     else
0071         m_child->bMoveUp->setEnabled(true);
0072 
0073     if (!m_tagSchemeModel->rowCount() || item == m_tagSchemeModel->index(m_tagSchemeModel->rowCount(QModelIndex())-1, 0, QModelIndex()))
0074         m_child->bMoveDown->setEnabled(false);
0075     else
0076         m_child->bMoveDown->setEnabled(true);
0077 }
0078 
0079 void TagGuesserConfigDlg::slotMoveUpClicked()
0080 {
0081     QModelIndex currentItem = m_child->lvSchemes->currentIndex();
0082     int row = currentItem.row();
0083 
0084     m_tagSchemeModel->insertRow(row - 1); // Insert in front of item above
0085     row++; // Now we're one row down
0086 
0087     QModelIndex newItem = m_tagSchemeModel->index(row - 2, 0);
0088 
0089     // Copy over, then delete old item
0090     currentItem = m_tagSchemeModel->index(row, 0);
0091     m_tagSchemeModel->setData(newItem, m_tagSchemeModel->data(currentItem, Qt::DisplayRole), Qt::DisplayRole);
0092     m_tagSchemeModel->removeRow(row);
0093 
0094     m_child->lvSchemes->setCurrentIndex(newItem);
0095     slotCurrentChanged(newItem);
0096 }
0097 
0098 void TagGuesserConfigDlg::slotMoveDownClicked()
0099 {
0100     QModelIndex currentItem = m_child->lvSchemes->currentIndex();
0101     int row = currentItem.row();
0102 
0103     m_tagSchemeModel->insertRow(row + 2); // Insert in front of 2 items below
0104 
0105     QModelIndex newItem = m_tagSchemeModel->index(row + 2, 0);
0106 
0107     // Copy over, then delete old item
0108     currentItem = m_tagSchemeModel->index(row, 0);
0109     m_tagSchemeModel->setData(newItem, m_tagSchemeModel->data(currentItem, Qt::DisplayRole), Qt::DisplayRole);
0110     m_tagSchemeModel->removeRow(row);
0111 
0112     newItem = m_tagSchemeModel->index(row + 1, 0);
0113     m_child->lvSchemes->setCurrentIndex(newItem);
0114     slotCurrentChanged(newItem);
0115 }
0116 
0117 void TagGuesserConfigDlg::slotAddClicked()
0118 {
0119     m_tagSchemeModel->insertRow(0, QModelIndex());
0120     m_child->lvSchemes->setCurrentIndex(m_tagSchemeModel->index(0, 0, QModelIndex()));
0121     m_child->lvSchemes->edit(m_child->lvSchemes->currentIndex());
0122     slotCurrentChanged(m_child->lvSchemes->currentIndex());
0123 }
0124 
0125 void TagGuesserConfigDlg::slotModifyClicked()
0126 {
0127     m_child->lvSchemes->edit(m_child->lvSchemes->currentIndex());
0128 }
0129 
0130 void TagGuesserConfigDlg::slotRemoveClicked()
0131 {
0132     m_tagSchemeModel->removeRow(m_child->lvSchemes->currentIndex().row(), QModelIndex());
0133     slotCurrentChanged(m_child->lvSchemes->currentIndex());
0134 }
0135 
0136 void TagGuesserConfigDlg::accept()
0137 {
0138     TagGuesser::setSchemeStrings(m_tagSchemeModel->stringList());
0139     QDialog::accept();
0140 }
0141 
0142 // vim: set et sw=4 tw=0 sta: