Commit 9844462a authored by Michael Pyne's avatar Michael Pyne

Port DirectoryList away from KDialog.

parent 4b413f6f
......@@ -19,40 +19,47 @@
#include <QCheckBox>
#include <QStringListModel>
#include <QtCore/QVariant>
#include <QVariant>
#include <QPushButton>
#include <QFileDialog>
#include <QStandardPaths>
#include <kfiledialog.h>
#include <klocale.h>
#include "juk_debug.h"
////////////////////////////////////////////////////////////////////////////////
// static helpers
////////////////////////////////////////////////////////////////////////////////
static QStringList defaultFolders()
{
return QStandardPaths::standardLocations(QStandardPaths::MusicLocation);
}
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
DirectoryList::DirectoryList(QStringList directories,
QStringList excludedDirectories,
DirectoryList::DirectoryList(const QStringList &directories,
const QStringList &excludedDirectories,
bool importPlaylists,
QWidget *parent) :
KDialog(parent),
m_dirListModel(0)
QWidget *parent)
: QDialog(parent)
, m_dirListModel(new QStringListModel(directories, this))
, m_excludedDirListModel(new QStringListModel(excludedDirectories, this))
{
if(directories.isEmpty()) {
directories = defaultFolders();
m_result.addedDirs = directories;
const auto defaultDirs = defaultFolders();
m_dirListModel->setStringList(defaultDirs);
m_result.addedDirs = defaultDirs;
}
m_dirListModel = new QStringListModel(directories, this);
m_excludedDirListModel = new QStringListModel(excludedDirectories, this);
setCaption(i18n("Folder List"));
setWindowTitle(i18n("Folder List"));
setModal(true);
showButtonSeparator(true);
setButtons(KDialog::Ok | KDialog::Cancel);
m_base = new DirectoryListBase(this);
setMainWidget(m_base);
auto layout = new QVBoxLayout(this);
layout->addWidget(m_base);
connect(m_base->addDirectoryButton, SIGNAL(clicked()),
SLOT(slotAddDirectory()));
......@@ -62,6 +69,8 @@ DirectoryList::DirectoryList(QStringList directories,
SLOT(slotAddExcludeDirectory()));
connect(m_base->removeExcludeDirectoryButton, SIGNAL(clicked()),
SLOT(slotRemoveExcludeDirectory()));
connect(m_base->dlgButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_base->dlgButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
m_base->directoryListView->setModel(m_dirListModel);
m_base->excludeDirectoryListView->setModel(m_excludedDirListModel);
......@@ -70,18 +79,13 @@ DirectoryList::DirectoryList(QStringList directories,
resize(QSize(440, 280).expandedTo(minimumSizeHint()));
}
DirectoryList::~DirectoryList()
{
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
int DirectoryList::exec()
{
m_result.status = static_cast<DialogCode>(KDialog::exec());
m_result.status = static_cast<QDialog::DialogCode>(QDialog::exec());
m_result.addPlaylists = m_base->importPlaylistsCheckBox->isChecked();
return m_result.status;
}
......@@ -92,8 +96,7 @@ int DirectoryList::exec()
void DirectoryList::slotAddDirectory()
{
QString dir = KFileDialog::getExistingDirectory();
QString dir = QFileDialog::getExistingDirectory();
if(dir.isEmpty())
return;
......@@ -139,8 +142,7 @@ void DirectoryList::slotRemoveDirectory()
void DirectoryList::slotAddExcludeDirectory()
{
QString dir = KFileDialog::getExistingDirectory();
QString dir = QFileDialog::getExistingDirectory();
if(dir.isEmpty())
return;
......@@ -175,20 +177,4 @@ void DirectoryList::slotRemoveExcludeDirectory()
m_result.excludedDirs = m_excludedDirListModel->stringList();
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
QStringList DirectoryList::defaultFolders()
{
QDir home = QDir::home();
if(home.cd("Music"))
return QStringList(home.path());
if(home.cd("music"))
return QStringList(home.path());
if(home.cd(i18n("Music")))
return QStringList(home.path());
return QStringList();
}
// vim: set et sw=4 tw=0 sta:
......@@ -14,16 +14,19 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DIRECTORYLIST_H
#define DIRECTORYLIST_H
#ifndef JUK_DIRECTORYLIST_H
#define JUK_DIRECTORYLIST_H
#include <QDialog>
#include <kdialog.h>
#include "ui_directorylistbase.h"
class QStringListModel;
class DirectoryListBase : public QWidget, public Ui::DirectoryListBase
{
Q_OBJECT
public:
DirectoryListBase(QWidget *parent) : QWidget(parent)
{
......@@ -31,7 +34,7 @@ public:
}
};
class DirectoryList : public KDialog
class DirectoryList : public QDialog
{
Q_OBJECT
......@@ -45,9 +48,11 @@ public:
bool addPlaylists;
};
DirectoryList(QStringList directories, QStringList excludeDirectories, bool importPlaylists,
QWidget *parent = 0);
virtual ~DirectoryList();
DirectoryList(
const QStringList &directories,
const QStringList &excludeDirectories,
bool importPlaylists,
QWidget *parent = nullptr);
Result dialogResult() const { return m_result; }
......@@ -67,8 +72,6 @@ private slots:
void slotRemoveExcludeDirectory();
private:
static QStringList defaultFolders();
QStringListModel *m_dirListModel;
QStringListModel *m_excludedDirListModel;
DirectoryListBase *m_base;
......
......@@ -187,6 +187,13 @@
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="dlgButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
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