Commit 19b0de32 authored by Sandro Andrade's avatar Sandro Andrade
Browse files

Remove wizard by now

parent 64bb8bc8
......@@ -3,14 +3,12 @@ set(minuet_SRCS
plugincontroller.cpp
uicontroller.cpp
exercisecontroller.cpp
minuetmainwindow.cpp
wizard.cpp
mainwindow.cpp
main.cpp
)
ki18n_wrap_ui(minuet_SRCS
settingsmidi.ui
wizardsystemcheck.ui
)
kconfig_add_kcfg_files(minuet_SRCS minuetsettings.kcfgc)
......
......@@ -20,10 +20,10 @@
**
****************************************************************************/
#include "minuetmainwindow.h"
#include "mainwindow.h"
#include "wizard.h"
#include "core.h"
#include "minuet_version.h"
#include <KMessageBox>
#include <KConfigDialog>
......@@ -41,7 +41,7 @@
Q_DECLARE_LOGGING_CATEGORY(MINUET)
Q_LOGGING_CATEGORY(MINUET, "minuet")
MinuetMainWindow::MinuetMainWindow(Minuet::Core *core, QWidget *parent, Qt::WindowFlags f) :
MainWindow::MainWindow(Minuet::Core *core, QWidget *parent, Qt::WindowFlags f) :
KXmlGuiWindow(parent, f),
m_quickView(new QQuickView),
m_initialGroup(KSharedConfig::openConfig(), "version")
......@@ -53,44 +53,26 @@ MinuetMainWindow::MinuetMainWindow(Minuet::Core *core, QWidget *parent, Qt::Wind
m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);
setCentralWidget(QWidget::createWindowContainer(m_quickView, this));
// KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollection());
QAction *action = new QAction(i18n("Run Configuration Wizard"), this);
action->setIcon(QIcon::fromTheme(QStringLiteral("tools-wizard")));
connect(action, &QAction::triggered, this, &MinuetMainWindow::runWizard);
actionCollection()->addAction(QStringLiteral("run_wizard"), action);
setupGUI(Keys | Save | Create);
foreach (QToolBar *toolBar, findChildren<QToolBar*>())
delete toolBar;
if (!m_initialGroup.exists())
runWizard();
}
MinuetMainWindow::~MinuetMainWindow()
MainWindow::~MainWindow()
{
delete m_quickView;
}
bool MinuetMainWindow::queryClose()
bool MainWindow::queryClose()
{
MinuetSettings::self()->save();
return true;
}
void MinuetMainWindow::runWizard()
{
QScopedPointer<Wizard> w (new Wizard(this));
if (w->exec() == QDialog::Accepted && w->isOk()) {
w->adjustSettings();
m_initialGroup.writeEntry("version", "1.0");
}
}
void MinuetMainWindow::settingsConfigure()
void MainWindow::settingsConfigure()
{
if (KConfigDialog::showDialog(QStringLiteral("settings")))
return;
......@@ -102,5 +84,6 @@ void MinuetMainWindow::settingsConfigure()
m_settingsMidi.cboMidiOutputPort->setCurrentIndex(m_settingsMidi.cboMidiOutputPort->findText(MinuetSettings::midiOutputPort()));
dialog->addPage(midiSettingsDialog, i18n("MIDI"), QStringLiteral("media-playback-start"));
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->exec();
delete dialog;
}
......@@ -20,8 +20,8 @@
**
****************************************************************************/
#ifndef MINUETMAINWINDOW_H
#define MINUETMAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_settingsmidi.h"
#include "minuetsettings.h"
......@@ -46,7 +46,7 @@ Q_DECLARE_LOGGING_CATEGORY(MINUET)
* @author Sandro S. Andrade <sandroandrade@kde.org>
* @version 0.1
*/
class MinuetMainWindow : public KXmlGuiWindow
class MainWindow : public KXmlGuiWindow
{
Q_OBJECT
......@@ -54,23 +54,17 @@ public:
/**
* Default Constructor
*/
MinuetMainWindow(Minuet::Core *core, QWidget *parent=0, Qt::WindowFlags f=KDE_DEFAULT_WINDOWFLAGS);
MainWindow(Minuet::Core *core, QWidget *parent=0, Qt::WindowFlags f=KDE_DEFAULT_WINDOWFLAGS);
/**
* Default Destructor
*/
virtual ~MinuetMainWindow();
virtual ~MainWindow();
protected:
virtual bool queryClose();
private Q_SLOTS:
/**
* Create a new window
*/
// void fileOpen();
void runWizard();
/**
* Open the settings dialog
*/
......@@ -82,5 +76,5 @@ private:
KConfigGroup m_initialGroup;
};
#endif // MINUETMAINWINDOW_H
#endif // MAINWINDOW_H
<?xml version="1.0" encoding="UTF-8"?>
<gui name="systemsettings"
version="1"
version="1.1"
xmlns="http://www.kde.org/standards/kxmlgui/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0
http://www.kde.org/standards/kxmlgui/1.0/kxmlgui.xsd">
<MenuBar>
<Menu name="settings" >
<Action name="run_wizard" />
</Menu>
</MenuBar>
<ToolBar noMerge="1" hidden="true" name="mainToolBar">
</ToolBar>
......
......@@ -29,7 +29,7 @@ namespace Minuet
UiController::UiController(QObject *parent)
: IUiController(parent),
m_mainWindow(new MinuetMainWindow(qobject_cast<Core *>(parent)))
m_mainWindow(new MainWindow(qobject_cast<Core *>(parent)))
{
}
......
......@@ -23,7 +23,7 @@
#ifndef MINUET_UICONTROLLER_H
#define MINUET_UICONTROLLER_H
#include "minuetmainwindow.h"
#include "mainwindow.h"
#include <interfaces/iuicontroller.h>
......@@ -43,7 +43,7 @@ public:
bool initialize(Core *core);
private:
QScopedPointer<MinuetMainWindow> m_mainWindow;
QScopedPointer<MainWindow> m_mainWindow;
};
}
......
/****************************************************************************
**
** Copyright (C) 2016 by Sandro S. Andrade <sandroandrade@kde.org>
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License or (at your option) version 3 or any later version
** accepted by the membership of KDE e.V. (or its successor approved
** by the membership of KDE e.V.), which shall act as a proxy
** defined in Section 14 of version 3 of the license.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "wizard.h"
#include "minuetsettings.h"
#include <KLocalizedString>
#include <QTimer>
#include <QLabel>
#include <QVBoxLayout>
#include <QDirIterator>
#include <QStandardPaths>
Wizard::Wizard(QWidget *parent, Qt::WindowFlags flags) :
QWizard(parent, flags),
m_okIcon (QIcon::fromTheme(QStringLiteral("dialog-ok"))),
m_badIcon (QIcon::fromTheme(QStringLiteral("dialog-close")))
{
setWindowTitle(i18n("Configuration Wizard"));
QWizardPage *page1 = new QWizardPage;
page1->setTitle(i18n("Welcome"));
QLabel *welcomeLabel = new QLabel(i18n("This is the first time you run Minuet. This wizard will let you adjust some basic settings, you will be ready to starting enhancing your music skills in a few seconds ..."), this);
welcomeLabel->setWordWrap(true);
QVBoxLayout *startLayout = new QVBoxLayout;
startLayout->addWidget(welcomeLabel);
page1->setLayout(startLayout);
addPage(page1);
QWizardPage *page2 = new QWizardPage;
page2->setTitle(i18n("Checking system"));
m_systemCheck.setupUi(page2);
WizardDelegate *listViewDelegate = new WizardDelegate(m_systemCheck.programList);
m_systemCheck.programList->setItemDelegate(listViewDelegate);
addPage(page2);
QTimer::singleShot(500, this, &Wizard::checkSystem);
}
bool Wizard::isOk() const
{
return m_systemCheckIsOk;
}
void Wizard::adjustSettings()
{
if (!m_timidityPath.isEmpty()) {
MinuetSettings::setTimidityLocation(m_timidityPath);
if (MinuetSettings::timidityParameters().isEmpty())
MinuetSettings::setTimidityParameters(QStringLiteral("-iA"));
if (MinuetSettings::midiOutputPort().isEmpty())
MinuetSettings::setMidiOutputPort(QStringLiteral("TiMidity:0"));
}
}
void Wizard::checkSystem()
{
m_systemCheckIsOk = false;
m_systemCheck.programList->setColumnWidth(0, 30);
m_systemCheck.programList->setIconSize(QSize(24, 24));
QTreeWidgetItem *item = addTreeWidgetItem(QStringLiteral("TiMidity++"), i18n("Required for playing MIDI files and exercises"));
m_timidityPath = QStandardPaths::findExecutable(QStringLiteral("timidity"));
if (m_timidityPath.isEmpty()) {
item->setIcon(0, m_badIcon);
return;
}
item = addTreeWidgetItem(i18n("TiMidity++ configuration file"), i18n("Required for setting up TiMidity++"));
QDirIterator it(QStringLiteral("/etc"), QDirIterator::Subdirectories);
QString timidityConfig;
while (it.hasNext()) {
QString file = it.next();
if (file.contains(QRegularExpression(QStringLiteral("timidity(\\+\\+)?.cfg")))) {
timidityConfig = file;
break;
}
}
if (!timidityConfig.isEmpty()) {
QFile timidityConfigFile(timidityConfig);
if (!timidityConfigFile.open(QIODevice::ReadOnly)) {
qWarning("Couldn't open TiMidity++ configuration file.");
return;
}
bool sourceFound = false;
QTextStream in(&timidityConfigFile);
while (!in.atEnd())
{
QString line = timidityConfigFile.readLine().simplified();
if (line.contains(QStringLiteral("source")) && !line.startsWith('#')) {
QRegularExpression regExp(QStringLiteral("source ([^/]*)\\.cfg"));
QRegularExpressionMatch match = regExp.match(line);
item = addTreeWidgetItem(i18n("TiMidity++ %1 sound source", match.captured(1)), i18n("Required for setting up TiMidity++ sound sources"));
sourceFound = true;
}
}
timidityConfigFile.close();
m_systemCheckIsOk = true;
if (!sourceFound) {
item = addTreeWidgetItem(i18n("A TiMidity++ sound source"), i18n("No TiMidity++ sound source found! Sounds won't work!"));
item->setIcon(0, m_badIcon);
return;
}
} else {
item->setIcon(0, m_badIcon);
return;
}
}
QTreeWidgetItem *Wizard::addTreeWidgetItem(const QString &text, const QString &subText)
{
QSize itemSize(20, fontMetrics().height() * 2.5);
QTreeWidgetItem *item = new QTreeWidgetItem(m_systemCheck.programList, QStringList() << QString() << text);
item->setData(1, Qt::UserRole, subText);
item->setSizeHint(0, itemSize);
item->setIcon(0, m_okIcon);
return item;
}
/****************************************************************************
**
** Copyright (C) 2016 by Sandro S. Andrade <sandroandrade@kde.org>
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License or (at your option) version 3 or any later version
** accepted by the membership of KDE e.V. (or its successor approved
** by the membership of KDE e.V.), which shall act as a proxy
** defined in Section 14 of version 3 of the license.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef WIZARD_H
#define WIZARD_H
#include "ui_wizardsystemcheck.h"
#include <QWizard>
#include <QPainter>
#include <QItemDelegate>
class WizardDelegate: public QItemDelegate
{
Q_OBJECT
public:
explicit WizardDelegate(QAbstractItemView *parent = 0)
: QItemDelegate(parent)
{
}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 1) {
painter->save();
QStyleOptionViewItem opt(option);
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
QFont font = painter->font();
font.setBold(true);
painter->setFont(font);
QRect r1 = option.rect;
r1.adjust(0, textMargin, 0, - textMargin);
int mid = (int)((r1.height() / 2));
r1.setBottom(r1.y() + mid);
QRect r2 = option.rect;
r2.setTop(r2.y() + mid);
painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
font.setBold(false);
painter->setFont(font);
QString subText = index.data(Qt::UserRole).toString();
painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText);
painter->restore();
} else {
QItemDelegate::paint(painter, option, index);
}
}
};
class Wizard : public QWizard
{
Q_OBJECT
public:
explicit Wizard(QWidget * parent = 0, Qt::WindowFlags flags = 0);
bool isOk() const;
void adjustSettings();
private Q_SLOTS:
void checkSystem();
private:
QTreeWidgetItem *addTreeWidgetItem(const QString &text, const QString &subText);
private:
bool m_systemCheckIsOk;
Ui::WizardSystemCheck m_systemCheck;
QIcon m_okIcon;
QIcon m_badIcon;
QString m_timidityPath;
};
#endif // WIZARD_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WizardSystemCheck</class>
<widget class="QWidget" name="WizardSystemCheck">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>236</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTreeWidget" name="programList">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
<column>
<property name="text">
<string notr="true">2</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<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