Commit c10535a7 authored by Michael Pyne's avatar Michael Pyne

More kde3support-- patches from Georg Grabler. This ports the tag guesser config dialog

to straight Qt/KDE 4.

svn path=/trunk/KDE/kdemultimedia/juk/; revision=1006069
parent 5f8ab2bc
......@@ -10,13 +10,13 @@
#include "tagguesser.h"
#include <kicon.h>
#include <k3listview.h>
#include <klocale.h>
#include <kpushbutton.h>
#include <klineedit.h>
#include <kapplication.h>
#include <QKeyEvent>
#include <QStringListModel>
TagGuesserConfigDlg::TagGuesserConfigDlg(QWidget *parent, const char *name)
: KDialog(parent)
......@@ -31,98 +31,102 @@ TagGuesserConfigDlg::TagGuesserConfigDlg(QWidget *parent, const char *name)
m_child = new TagGuesserConfigDlgWidget(this);
setMainWidget(m_child);
m_child->lvSchemes->setItemsRenameable(true);
m_child->lvSchemes->setSorting(-1);
m_child->lvSchemes->setDefaultRenameAction(Q3ListView::Accept);
m_child->bMoveUp->setIcon(KIcon("arrow-up"));
m_child->bMoveDown->setIcon(KIcon("arrow-down"));
const QStringList schemes = TagGuesser::schemeStrings();
QStringList::ConstIterator it = schemes.begin();
QStringList::ConstIterator end = schemes.end();
for (; it != end; ++it) {
K3ListViewItem *item = new K3ListViewItem(m_child->lvSchemes, *it);
item->moveItem(m_child->lvSchemes->lastItem());
}
connect(m_child->lvSchemes, SIGNAL(currentChanged(Q3ListViewItem *)),
this, SLOT(slotCurrentChanged(Q3ListViewItem *)));
connect(m_child->lvSchemes, SIGNAL(doubleClicked(Q3ListViewItem *, const QPoint &, int)),
this, SLOT(slotRenameItem(Q3ListViewItem *, const QPoint &, int)));
m_tagSchemeModel = new QStringListModel(m_child->lvSchemes);
m_child->lvSchemes->setModel(m_tagSchemeModel);
m_child->lvSchemes->setHeaderHidden(true);
m_tagSchemeModel->setStringList(TagGuesser::schemeStrings());
connect(m_child->lvSchemes, SIGNAL(clicked(QModelIndex)), this, SLOT(slotCurrentChanged(QModelIndex)));
connect(m_child->bMoveUp, SIGNAL(clicked()), this, SLOT(slotMoveUpClicked()));
connect(m_child->bMoveDown, SIGNAL(clicked()), this, SLOT(slotMoveDownClicked()));
connect(m_child->bAdd, SIGNAL(clicked()), this, SLOT(slotAddClicked()));
connect(m_child->bModify, SIGNAL(clicked()), this, SLOT(slotModifyClicked()));
connect(m_child->bRemove, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));
m_child->lvSchemes->setSelected(m_child->lvSchemes->firstChild(), true);
slotCurrentChanged(m_child->lvSchemes->currentItem());
resize( 400, 300 );
}
void TagGuesserConfigDlg::accept()
void TagGuesserConfigDlg::slotCurrentChanged(QModelIndex item)
{
if(m_child->lvSchemes->renameLineEdit()) {
QKeyEvent returnKeyPress(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
KApplication::sendEvent(m_child->lvSchemes->renameLineEdit(), &returnKeyPress);
}
QStringList schemes;
for (Q3ListViewItem *it = m_child->lvSchemes->firstChild(); it; it = it->nextSibling())
schemes += it->text(0);
TagGuesser::setSchemeStrings(schemes);
KDialog::accept();
}
m_child->bRemove->setEnabled(m_tagSchemeModel->rowCount() != 0);
void TagGuesserConfigDlg::slotCurrentChanged(Q3ListViewItem *item)
{
m_child->bMoveUp->setEnabled(item != 0 && item->itemAbove() != 0);
m_child->bMoveDown->setEnabled(item != 0 && item->itemBelow() != 0);
m_child->bModify->setEnabled(item != 0);
m_child->bRemove->setEnabled(item != 0);
}
// Ensure up/down buttons are appropriately enabled.
void TagGuesserConfigDlg::slotRenameItem(Q3ListViewItem *item, const QPoint &, int c)
{
m_child->lvSchemes->rename(item, c);
if (!m_tagSchemeModel->rowCount() || item == m_tagSchemeModel->index(0, 0, QModelIndex()))
m_child->bMoveUp->setEnabled(false);
else
m_child->bMoveUp->setEnabled(true);
if (!m_tagSchemeModel->rowCount() || item == m_tagSchemeModel->index(m_tagSchemeModel->rowCount(QModelIndex())-1, 0, QModelIndex()))
m_child->bMoveDown->setEnabled(false);
else
m_child->bMoveDown->setEnabled(true);
}
void TagGuesserConfigDlg::slotMoveUpClicked()
{
Q3ListViewItem *item = m_child->lvSchemes->currentItem();
if(item->itemAbove() == m_child->lvSchemes->firstChild())
item->itemAbove()->moveItem(item);
else
item->moveItem(item->itemAbove()->itemAbove());
m_child->lvSchemes->ensureItemVisible(item);
slotCurrentChanged(item);
QModelIndex currentItem = m_child->lvSchemes->currentIndex();
int row = currentItem.row();
m_tagSchemeModel->insertRow(row - 1); // Insert in front of item above
row++; // Now we're one row down
QModelIndex newItem = m_tagSchemeModel->index(row - 2, 0);
// Copy over, then delete old item
currentItem = m_tagSchemeModel->index(row, 0);
m_tagSchemeModel->setData(newItem, m_tagSchemeModel->data(currentItem, Qt::DisplayRole), Qt::DisplayRole);
m_tagSchemeModel->removeRow(row);
m_child->lvSchemes->setCurrentIndex(newItem);
slotCurrentChanged(newItem);
}
void TagGuesserConfigDlg::slotMoveDownClicked()
{
Q3ListViewItem *item = m_child->lvSchemes->currentItem();
item->moveItem(item->itemBelow());
m_child->lvSchemes->ensureItemVisible(item);
slotCurrentChanged(item);
QModelIndex currentItem = m_child->lvSchemes->currentIndex();
int row = currentItem.row();
m_tagSchemeModel->insertRow(row + 2); // Insert in front of 2 items below
QModelIndex newItem = m_tagSchemeModel->index(row + 2, 0);
// Copy over, then delete old item
currentItem = m_tagSchemeModel->index(row, 0);
m_tagSchemeModel->setData(newItem, m_tagSchemeModel->data(currentItem, Qt::DisplayRole), Qt::DisplayRole);
m_tagSchemeModel->removeRow(row);
newItem = m_tagSchemeModel->index(row + 1, 0);
m_child->lvSchemes->setCurrentIndex(newItem);
slotCurrentChanged(newItem);
}
void TagGuesserConfigDlg::slotAddClicked()
{
K3ListViewItem *item = new K3ListViewItem(m_child->lvSchemes);
m_child->lvSchemes->rename(item, 0);
m_tagSchemeModel->insertRow(0, QModelIndex());
m_child->lvSchemes->setCurrentIndex(m_tagSchemeModel->index(0, 0, QModelIndex()));
m_child->lvSchemes->edit(m_child->lvSchemes->currentIndex());
slotCurrentChanged(m_child->lvSchemes->currentIndex());
}
void TagGuesserConfigDlg::slotModifyClicked()
{
m_child->lvSchemes->rename(m_child->lvSchemes->currentItem(), 0);
m_child->lvSchemes->edit(m_child->lvSchemes->currentIndex());
}
void TagGuesserConfigDlg::slotRemoveClicked()
{
delete m_child->lvSchemes->currentItem();
m_tagSchemeModel->removeRow(m_child->lvSchemes->currentIndex().row(), QModelIndex());
slotCurrentChanged(m_child->lvSchemes->currentIndex());
}
#include "tagguesserconfigdlg.moc"
void TagGuesserConfigDlg::accept()
{
TagGuesser::setSchemeStrings(m_tagSchemeModel->stringList());
KDialog::accept();
}
// vim: set et sw=4 tw=0 sta:
......@@ -12,7 +12,7 @@
#include <kdialog.h>
#include "ui_tagguesserconfigdlgwidget.h"
class Q3ListViewItem;
class QStringListModel;
class TagGuesserConfigDlgWidget : public QWidget, public Ui::TagGuesserConfigDlgWidget
......@@ -33,8 +33,7 @@ class TagGuesserConfigDlg : public KDialog
virtual void accept();
private slots:
void slotCurrentChanged(Q3ListViewItem *item);
void slotRenameItem(Q3ListViewItem *item, const QPoint &p, int c);
void slotCurrentChanged(QModelIndex item);
void slotMoveUpClicked();
void slotMoveDownClicked();
void slotAddClicked();
......@@ -43,6 +42,7 @@ class TagGuesserConfigDlg : public KDialog
private:
TagGuesserConfigDlgWidget *m_child;
QStringListModel *m_tagSchemeModel;
};
#endif // TAGGUESSERCONFIGDLG_H
......
<ui version="4.0" stdsetdef="1" >
<author>Frerich Raabe &lt;raabe@kde.org></author>
<class>TagGuesserConfigDlgWidget</class>
<widget class="QWidget" name="TagGuesserConfigDlgWidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>480</height>
</rect>
</property>
<layout class="QGridLayout" >
<item rowspan="5" row="0" column="0" colspan="1" >
<widget class="K3ListView" name="lvSchemes" >
<property name="frameShape" >
<enum>StyledPanel</enum>
</property>
<property name="frameShadow" >
<enum>Sunken</enum>
</property>
<property name="fullWidth" >
<bool>true</bool>
</property>
<property name="toolTip" stdset="0" >
<string>Currently used file name schemes</string>
</property>
<property name="whatsThis" stdset="0" >
<string>Here you can see the currently configured file name schemes which the "Suggest" button in the tag editor uses to extract tag information from a file name. Each string may contain one of the following placeholders:&lt;ul>
&lt;li>%t: Title&lt;/li>
&lt;li>%a: Artist&lt;/li>
&lt;li>%A: Album&lt;/li>
&lt;li>%T: Track&lt;/li>
&lt;li>%c: Comment&lt;/li>
&lt;/ul>
For example, the file name scheme "[%T] %a - %t" would match "[01] Deep Purple - Smoke on the water" but not "(Deep Purple) Smoke on the water". For that second name, you would use the scheme "(%a) %t".&lt;p/>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>Frerich Raabe &lt;raabe@kde.org&gt;</author>
<class>TagGuesserConfigDlgWidget</class>
<widget class="QWidget" name="TagGuesserConfigDlgWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>480</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="5">
<widget class="QTreeView" name="lvSchemes">
<property name="toolTip">
<string>Currently used file name schemes</string>
</property>
<property name="whatsThis">
<string>Here you can see the currently configured file name schemes which the &quot;Suggest&quot; button in the tag editor uses to extract tag information from a file name. Each string may contain one of the following placeholders:&lt;ul&gt;
&lt;li&gt;%t: Title&lt;/li&gt;
&lt;li&gt;%a: Artist&lt;/li&gt;
&lt;li&gt;%A: Album&lt;/li&gt;
&lt;li&gt;%T: Track&lt;/li&gt;
&lt;li&gt;%c: Comment&lt;/li&gt;
&lt;/ul&gt;
For example, the file name scheme &quot;[%T] %a - %t&quot; would match &quot;[01] Deep Purple - Smoke on the water&quot; but not &quot;(Deep Purple) Smoke on the water&quot;. For that second name, you would use the scheme &quot;(%a) %t&quot;.&lt;p/&gt;
Note that the order in which the schemes appear in the list is relevant, since the tag guesser will go through the list from the top to the bottom, and use the first matching scheme.</string>
</property>
<column>
<property name="text" >
<string>File Name Scheme</string>
</property>
<property name="clickable" >
<bool>false</bool>
</property>
<property name="resizable" >
<bool>false</bool>
</property>
</column>
</widget>
</item>
<item rowspan="1" row="1" column="1" colspan="3" >
<widget class="KPushButton" name="bAdd" >
<property name="text" >
<string>&amp;Add</string>
</property>
<property name="toolTip" stdset="0" >
<string>Add a new scheme</string>
</property>
<property name="whatsThis" stdset="0" >
<string>Press this button to add a new file name scheme to the end of the list.</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QToolButton" name="bMoveUp" >
<property name="text" >
<string/>
</property>
<property name="toolTip" stdset="0" >
<string>Move scheme up</string>
</property>
<property name="whatsThis" stdset="0" >
<string>Press this button to move the currently selected scheme one step upwards.</string>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QToolButton" name="bMoveDown" >
<property name="text" >
<string/>
</property>
<property name="toolTip" stdset="0" >
<string>Move scheme down</string>
</property>
<property name="whatsThis" stdset="0" >
<string>Press this button to move the currently selected scheme one step downwards.</string>
</property>
</widget>
</item>
<item rowspan="1" row="2" column="1" colspan="3" >
<widget class="KPushButton" name="bModify" >
<property name="text" >
<string>&amp;Modify</string>
</property>
<property name="toolTip" stdset="0" >
<string>Modify scheme</string>
</property>
<property name="whatsThis" stdset="0" >
<string>Press this button to modify the currently selected scheme.</string>
</property>
</widget>
</item>
<item rowspan="1" row="3" column="1" colspan="3" >
<widget class="KPushButton" name="bRemove" >
<property name="text" >
<string>&amp;Remove</string>
</property>
<property name="toolTip" stdset="0" >
<string>Remove scheme</string>
</property>
<property name="whatsThis" stdset="0" >
<string>Press this button to remove the currently selected scheme from the list.</string>
</property>
</widget>
</item>
<item row="4" column="2" >
<spacer name="spacer1" >
<property name="sizeHint" >
<size>
<width>20</width>
<height>130</height>
</size>
</property>
<property name="sizeType" >
<enum>Expanding</enum>
</property>
<property name="orientation" >
<enum>Vertical</enum>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>K3ListView</class>
<extends>Q3ListView</extends>
<header>k3listview.h</header>
</customwidget>
</customwidgets>
<includes>
<include location="local" >k3listview.h</include>
<include location="local" >kpushbutton.h</include>
</includes>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="bMoveUp">
<property name="toolTip">
<string>Move scheme up</string>
</property>
<property name="whatsThis">
<string>Press this button to move the currently selected scheme one step upwards.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="bMoveDown">
<property name="toolTip">
<string>Move scheme down</string>
</property>
<property name="whatsThis">
<string>Press this button to move the currently selected scheme one step downwards.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="KPushButton" name="bAdd">
<property name="toolTip">
<string>Add a new scheme</string>
</property>
<property name="whatsThis">
<string>Press this button to add a new file name scheme to the end of the list.</string>
</property>
<property name="text">
<string>&amp;Add</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="KPushButton" name="bModify">
<property name="toolTip">
<string>Modify scheme</string>
</property>
<property name="whatsThis">
<string>Press this button to modify the currently selected scheme.</string>
</property>
<property name="text">
<string>&amp;Modify</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="KPushButton" name="bRemove">
<property name="toolTip">
<string>Remove scheme</string>
</property>
<property name="whatsThis">
<string>Press this button to remove the currently selected scheme from the list.</string>
</property>
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item row="4" column="2">
<spacer name="spacer1">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>130</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
</customwidgets>
<includes>
<include location="local">kpushbutton.h</include>
</includes>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment