summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-03-11 22:19:17 +0100
committerPetr Mrázek <peterix@gmail.com>2013-03-11 22:19:17 +0100
commit46f93311afc9f1e2afc306f63cee0e4f462758e2 (patch)
treecc945d66e6ca5e68c43b354d3f8f6d6e70cf5326 /gui
parent36396f7c6aca9fcc61c8620e10c31ed2c8999ebd (diff)
downloadMultiMC-46f93311afc9f1e2afc306f63cee0e4f462758e2.tar
MultiMC-46f93311afc9f1e2afc306f63cee0e4f462758e2.tar.gz
MultiMC-46f93311afc9f1e2afc306f63cee0e4f462758e2.tar.lz
MultiMC-46f93311afc9f1e2afc306f63cee0e4f462758e2.tar.xz
MultiMC-46f93311afc9f1e2afc306f63cee0e4f462758e2.zip
Instance view, model, delegate.
Diffstat (limited to 'gui')
-rw-r--r--gui/instancedelegate.cpp222
-rw-r--r--gui/instancedelegate.h12
-rw-r--r--gui/instancemodel.cpp92
-rw-r--r--gui/instancemodel.h38
-rw-r--r--gui/mainwindow.cpp176
-rw-r--r--gui/mainwindow.h21
-rw-r--r--gui/mainwindow.ui16
7 files changed, 499 insertions, 78 deletions
diff --git a/gui/instancedelegate.cpp b/gui/instancedelegate.cpp
new file mode 100644
index 00000000..dac2dacb
--- /dev/null
+++ b/gui/instancedelegate.cpp
@@ -0,0 +1,222 @@
+#include "instancedelegate.h"
+#include <QPainter>
+#include <QTextOption>
+#include <QTextLayout>
+#include <QApplication>
+#include <QtCore/qmath.h>
+
+// Origin: Qt
+static void viewItemTextLayout ( QTextLayout &textLayout, int lineWidth, qreal &height, qreal &widthUsed )
+{
+ height = 0;
+ widthUsed = 0;
+ textLayout.beginLayout();
+ while ( true )
+ {
+ QTextLine line = textLayout.createLine();
+ if ( !line.isValid() )
+ break;
+ line.setLineWidth ( lineWidth );
+ line.setPosition ( QPointF ( 0, height ) );
+ height += line.height();
+ widthUsed = qMax ( widthUsed, line.naturalTextWidth() );
+ }
+ textLayout.endLayout();
+}
+
+#define QFIXED_MAX (INT_MAX/256)
+
+ListViewDelegate::ListViewDelegate ( QObject* parent ) : QStyledItemDelegate ( parent )
+{
+
+}
+
+void drawSelectionRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect)
+{
+ if (!(option.state & QStyle::State_Selected))
+ return;
+ painter->fillRect ( rect, option.palette.brush ( QPalette::Highlight ) );
+}
+
+void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect)
+{
+ if (!(option.state & QStyle::State_HasFocus))
+ return;
+ QStyleOptionFocusRect opt;
+ opt.direction = option.direction;
+ opt.fontMetrics = option.fontMetrics;
+ opt.palette = option.palette;
+ opt.rect = rect;
+ //opt.state = option.state | QStyle::State_KeyboardFocusChange | QStyle::State_Item;
+ auto col = option.state & QStyle::State_Selected ? QPalette::Highlight : QPalette::Base;
+ opt.backgroundColor = option.palette.color(col);
+ // Apparently some widget styles expect this hint to not be set
+ painter->setRenderHint(QPainter::Antialiasing, false);
+
+ QStyle *style = option.widget ? option.widget->style() : QApplication::style();
+
+ style->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, painter, option.widget);
+
+ painter->setRenderHint(QPainter::Antialiasing);
+}
+
+static QSize viewItemTextSize ( const QStyleOptionViewItemV4 *option )
+{
+ QStyle *style = option->widget ? option->widget->style() : QApplication::style();
+ QTextOption textOption;
+ textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere );
+ QTextLayout textLayout;
+ textLayout.setTextOption ( textOption );
+ textLayout.setFont ( option->font );
+ textLayout.setText ( option->text );
+ const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, option, option->widget ) + 1;
+ QRect bounds ( 0,0,100 - 2*textMargin,600 );
+ qreal height = 0, widthUsed = 0;
+ viewItemTextLayout ( textLayout, bounds.width(), height, widthUsed );
+ const QSize size ( qCeil ( widthUsed ), qCeil ( height ) );
+ return QSize ( size.width() + 2 * textMargin, size.height() );
+}
+
+void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
+{
+ QStyleOptionViewItemV4 opt = option;
+ initStyleOption ( &opt, index );
+ painter->save();
+ painter->setClipRect ( opt.rect );
+
+ opt.features |= QStyleOptionViewItem::WrapText;
+ opt.text = index.data().toString();
+ opt.textElideMode = Qt::ElideRight;
+ opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter;
+
+ QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
+
+ //const int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize);
+ const int iconSize = 48;
+ QRect iconbox = opt.rect;
+ const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, 0, opt.widget ) + 1;
+ QRect textRect = opt.rect;
+ QRect textHighlightRect = textRect;
+ // clip the decoration on top, remove width padding
+ textRect.adjust ( textMargin,iconSize + textMargin + 5,-textMargin,0 );
+
+ textHighlightRect.adjust ( 0,iconSize + 5,0,0 );
+
+ // draw background
+ {
+ QSize textSize = viewItemTextSize ( &opt );
+ QPalette::ColorGroup cg;
+ QStyleOptionViewItemV4 opt2(opt);
+
+ if((opt.widget && opt.widget->isEnabled()) || (opt.state & QStyle::State_Enabled))
+ {
+ if(! ( opt.state & QStyle::State_Active ))
+ cg = QPalette::Inactive;
+ else
+ cg = QPalette::Normal;
+ }
+ else
+ {
+ cg = QPalette::Disabled;
+ }
+ opt2.palette.setCurrentColorGroup(cg);
+
+ // fill in background, if any
+ if ( opt.backgroundBrush.style() != Qt::NoBrush )
+ {
+ QPointF oldBO = painter->brushOrigin();
+ painter->setBrushOrigin ( opt.rect.topLeft() );
+ painter->fillRect ( opt.rect, opt.backgroundBrush );
+ painter->setBrushOrigin ( oldBO );
+ }
+
+ if ( opt.showDecorationSelected )
+ {
+ drawSelectionRect(painter,opt2, opt.rect);
+ drawFocusRect(painter,opt2, opt.rect);
+ //painter->fillRect ( opt.rect, opt.palette.brush ( cg, QPalette::Highlight ) );
+ }
+ else
+ {
+
+ //if ( opt.state & QStyle::State_Selected )
+ {
+ //QRect textRect = subElementRect ( QStyle::SE_ItemViewItemText, opt, opt.widget );
+ //painter->fillRect ( textHighlightRect, opt.palette.brush ( cg, QPalette::Highlight ) );
+ drawSelectionRect(painter,opt2, textHighlightRect);
+ drawFocusRect(painter,opt2, textHighlightRect);
+ }
+ }
+ }
+
+ // draw the icon
+ {
+ QIcon::Mode mode = QIcon::Normal;
+ if ( ! ( opt.state & QStyle::State_Enabled ) )
+ mode = QIcon::Disabled;
+ else if ( opt.state & QStyle::State_Selected )
+ mode = QIcon::Selected;
+ QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off;
+
+ iconbox.setHeight ( iconSize );
+ opt.icon.paint ( painter, iconbox, Qt::AlignCenter, mode, state );
+ }
+ // set the text colors
+ QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
+ if ( cg == QPalette::Normal && ! ( opt.state & QStyle::State_Active ) )
+ cg = QPalette::Inactive;
+ if ( opt.state & QStyle::State_Selected )
+ {
+ painter->setPen ( opt.palette.color ( cg, QPalette::HighlightedText ) );
+ }
+ else
+ {
+ painter->setPen ( opt.palette.color ( cg, QPalette::Text ) );
+ }
+
+ // draw the text
+ QTextOption textOption;
+ textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere );
+ textOption.setTextDirection ( opt.direction );
+ textOption.setAlignment ( QStyle::visualAlignment ( opt.direction, opt.displayAlignment ) );
+ QTextLayout textLayout;
+ textLayout.setTextOption ( textOption );
+ textLayout.setFont ( opt.font );
+ textLayout.setText ( opt.text );
+
+ qreal width, height;
+ viewItemTextLayout ( textLayout, iconbox.width(), height, width );
+
+ const int lineCount = textLayout.lineCount();
+
+ const QRect layoutRect = QStyle::alignedRect ( opt.direction, opt.displayAlignment, QSize ( iconbox.width(), int ( height ) ), textRect );
+ const QPointF position = layoutRect.topLeft();
+ for ( int i = 0; i < lineCount; ++i )
+ {
+ const QTextLine line = textLayout.lineAt ( i );
+ line.draw ( painter, position );
+ }
+
+ painter->restore();
+}
+
+
+QSize ListViewDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
+{
+ QStyleOptionViewItemV4 opt = option;
+ initStyleOption ( &opt, index );
+ opt.features |= QStyleOptionViewItem::WrapText;
+ opt.text = index.data().toString();
+ opt.textElideMode = Qt::ElideRight;
+ opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter;
+
+ QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
+ const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, &option, opt.widget ) + 1;
+ int height = 48 + textMargin * 2 + 5; // TODO: turn constants into variables
+ QSize szz = viewItemTextSize ( &opt );
+ height += szz.height();
+ // FIXME: maybe the icon items could scale and keep proportions?
+ QSize sz ( 100,height );
+ return sz;
+}
+
diff --git a/gui/instancedelegate.h b/gui/instancedelegate.h
new file mode 100644
index 00000000..c80f95a5
--- /dev/null
+++ b/gui/instancedelegate.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <QStyledItemDelegate>
+
+class ListViewDelegate : public QStyledItemDelegate
+{
+public:
+ explicit ListViewDelegate ( QObject* parent = 0 );
+protected:
+ void paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
+ QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
+}; \ No newline at end of file
diff --git a/gui/instancemodel.cpp b/gui/instancemodel.cpp
new file mode 100644
index 00000000..73d0dbc1
--- /dev/null
+++ b/gui/instancemodel.cpp
@@ -0,0 +1,92 @@
+#include "instancemodel.h"
+#include <instance.h>
+#include <QIcon>
+
+InstanceModel::InstanceModel ( const InstanceList& instances, QObject *parent )
+ : QAbstractListModel ( parent ), m_instances ( &instances )
+{
+ cachedIcon = QIcon(":/icons/multimc/scalable/apps/multimc.svg");
+}
+
+int InstanceModel::rowCount ( const QModelIndex& parent ) const
+{
+ Q_UNUSED ( parent );
+ return m_instances->count();
+}
+
+QModelIndex InstanceModel::index ( int row, int column, const QModelIndex& parent ) const
+{
+ Q_UNUSED ( parent );
+ if ( row < 0 || row >= m_instances->count() )
+ return QModelIndex();
+ return createIndex ( row, column, ( void* ) m_instances->at ( row ).data() );
+}
+
+QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
+{
+ if ( !index.isValid() )
+ {
+ return QVariant();
+ }
+ Instance *pdata = static_cast<Instance*> ( index.internalPointer() );
+ switch ( role )
+ {
+ case InstancePointerRole:
+ {
+ QVariant v = qVariantFromValue((void *) pdata);
+ return v;
+ }
+ case Qt::DisplayRole:
+ {
+ return pdata->name();
+ }
+ case Qt::ToolTipRole:
+ {
+ return pdata->rootDir();
+ }
+ case Qt::DecorationRole:
+ {
+ // FIXME: replace with an icon cache
+ return cachedIcon;
+ }
+ // for now.
+ case KCategorizedSortFilterProxyModel::CategorySortRole:
+ case KCategorizedSortFilterProxyModel::CategoryDisplayRole:
+ {
+ return "IT'S A GROUP";
+ }
+ default:
+ break;
+ }
+ return QVariant();
+}
+
+Qt::ItemFlags InstanceModel::flags ( const QModelIndex& index ) const
+{
+ Qt::ItemFlags f;
+ if ( index.isValid() )
+ {
+ f |= ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+ }
+ return f;
+}
+
+InstanceProxyModel::InstanceProxyModel ( QObject *parent )
+ : KCategorizedSortFilterProxyModel ( parent )
+{
+ // disable since by default we are globally sorting by date:
+ setCategorizedModel(true);
+}
+
+bool InstanceProxyModel::subSortLessThan (
+ const QModelIndex& left, const QModelIndex& right ) const
+{
+ Instance *pdataLeft = static_cast<Instance*> ( left.internalPointer() );
+ Instance *pdataRight = static_cast<Instance*> ( right.internalPointer() );
+ //kDebug() << *pdataLeft << *pdataRight;
+ return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0;
+ //return pdataLeft->name() < pdataRight->name();
+}
+
+#include "instancemodel.moc"
+
diff --git a/gui/instancemodel.h b/gui/instancemodel.h
new file mode 100644
index 00000000..995c51ec
--- /dev/null
+++ b/gui/instancemodel.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <QAbstractListModel>
+#include "kcategorizedsortfilterproxymodel.h"
+#include "instancelist.h"
+#include <QIcon>
+
+class InstanceModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum AdditionalRoles
+ {
+ InstancePointerRole = 0x34B1CB48 ///< Return pointer to real instance
+ };
+ explicit InstanceModel ( const InstanceList& instances,
+ QObject *parent = 0 );
+
+ QModelIndex index ( int row, int column = 0,
+ const QModelIndex& parent = QModelIndex() ) const;
+ int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
+ QVariant data ( const QModelIndex& index, int role ) const;
+ Qt::ItemFlags flags ( const QModelIndex& index ) const;
+
+private:
+ const InstanceList* m_instances;
+ QIcon cachedIcon;
+};
+
+class InstanceProxyModel : public KCategorizedSortFilterProxyModel
+{
+public:
+ explicit InstanceProxyModel ( QObject *parent = 0 );
+
+protected:
+ virtual bool subSortLessThan ( const QModelIndex& left, const QModelIndex& right ) const;
+};
+
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 6866da28..e691c8c4 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -7,7 +7,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@@ -40,45 +40,94 @@
#include "gui/browserdialog.h"
#include "gui/aboutdialog.h"
+#include "kcategorizedview.h"
+#include "kcategorydrawer.h"
+
#include "instancelist.h"
#include "appsettings.h"
#include "version.h"
#include "logintask.h"
+#include <instance.h>
+
+#include "instancemodel.h"
+#include "instancedelegate.h"
// Opens the given file in the default application.
// TODO: Move this somewhere.
-void openInDefaultProgram(QString filename);
+void openInDefaultProgram ( QString filename );
-MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow),
- instList(globalSettings->get("InstanceDir").toString())
+MainWindow::MainWindow ( QWidget *parent ) :
+ QMainWindow ( parent ),
+ ui ( new Ui::MainWindow ),
+ instList ( globalSettings->get ( "InstanceDir" ).toString() )
{
- ui->setupUi(this);
+ ui->setupUi ( this );
+ // Create the widget
+ instList.loadList();
- setWindowTitle(QString("MultiMC %1").arg(Version::current.toString()));
+ view = new KCategorizedView ( ui->centralWidget );
+ drawer = new KCategoryDrawer ( view );
+
+ view->setSelectionMode ( QAbstractItemView::SingleSelection );
+ //view->setSpacing( KDialog::spacingHint() );
+ view->setCategoryDrawer ( drawer );
+ view->setCollapsibleBlocks ( true );
+ view->setViewMode ( QListView::IconMode );
+ view->setFlow ( QListView::LeftToRight );
+ view->setWordWrap(true);
+ view->setMouseTracking ( true );
+ view->viewport()->setAttribute ( Qt::WA_Hover );
+ auto delegate = new ListViewDelegate();
+ view->setItemDelegate(delegate);
+ view->setSpacing(10);
+
+ model = new InstanceModel ( instList,this );
+ proxymodel = new InstanceProxyModel ( this );
+ proxymodel->setSortRole ( KCategorizedSortFilterProxyModel::CategorySortRole );
+ proxymodel->setFilterRole ( KCategorizedSortFilterProxyModel::CategorySortRole );
+ //proxymodel->setDynamicSortFilter ( true );
+ proxymodel->setSourceModel ( model );
+ proxymodel->sort ( 0 );
+
+ view->setFrameShape ( QFrame::NoFrame );
+
+ ui->horizontalLayout->addWidget ( view );
+ setWindowTitle ( QString ( "MultiMC %1" ).arg ( Version::current.toString() ) );
// TODO: Make this work with the new settings system.
// restoreGeometry(settings->getConfig().value("MainWindowGeometry", saveGeometry()).toByteArray());
// restoreState(settings->getConfig().value("MainWindowState", saveState()).toByteArray());
-
- instList.loadList();
+ view->setModel ( proxymodel );
+ connect(view, SIGNAL(doubleClicked(const QModelIndex &)),
+ this, SLOT(instanceActivated(const QModelIndex &)));
+
}
MainWindow::~MainWindow()
{
delete ui;
+ delete proxymodel;
+ delete model;
+ delete drawer;
+}
+
+void MainWindow::instanceActivated ( QModelIndex index )
+{
+ if(!index.isValid())
+ return;
+ Instance * inst = (Instance *) index.data(InstanceModel::InstancePointerRole).value<void *>();
+ doLogin(inst->id());
}
void MainWindow::on_actionAddInstance_triggered()
{
- NewInstanceDialog *newInstDlg = new NewInstanceDialog(this);
+ NewInstanceDialog *newInstDlg = new NewInstanceDialog ( this );
newInstDlg->exec();
}
void MainWindow::on_actionViewInstanceFolder_triggered()
{
- openInDefaultProgram(globalSettings->get("InstanceDir").toString());
+ openInDefaultProgram ( globalSettings->get ( "InstanceDir" ).toString() );
}
void MainWindow::on_actionRefresh_triggered()
@@ -88,115 +137,126 @@ void MainWindow::on_actionRefresh_triggered()
void MainWindow::on_actionViewCentralModsFolder_triggered()
{
- openInDefaultProgram(globalSettings->get("CentralModsDir").toString());
+ openInDefaultProgram ( globalSettings->get ( "CentralModsDir" ).toString() );
}
void MainWindow::on_actionCheckUpdate_triggered()
{
-
+
}
void MainWindow::on_actionSettings_triggered()
{
- SettingsDialog dialog(this);
+ SettingsDialog dialog ( this );
dialog.exec();
}
void MainWindow::on_actionReportBug_triggered()
{
- //QDesktopServices::openUrl(QUrl("http://bugs.forkk.net/"));
- openWebPage(QUrl("http://bugs.forkk.net/"));
+ //QDesktopServices::openUrl(QUrl("http://bugs.forkk.net/"));
+ openWebPage ( QUrl ( "http://bugs.forkk.net/" ) );
}
void MainWindow::on_actionNews_triggered()
{
- //QDesktopServices::openUrl(QUrl("http://news.forkk.net/"));
- openWebPage(QUrl("http://news.forkk.net/"));
+ //QDesktopServices::openUrl(QUrl("http://news.forkk.net/"));
+ openWebPage ( QUrl ( "http://news.forkk.net/" ) );
}
void MainWindow::on_actionAbout_triggered()
{
- AboutDialog dialog(this);
- dialog.exec();
+ AboutDialog dialog ( this );
+ dialog.exec();
}
-void MainWindow::on_mainToolBar_visibilityChanged(bool)
+void MainWindow::on_mainToolBar_visibilityChanged ( bool )
{
// Don't allow hiding the main toolbar.
// This is the only way I could find to prevent it... :/
- ui->mainToolBar->setVisible(true);
+ ui->mainToolBar->setVisible ( true );
}
-void MainWindow::closeEvent(QCloseEvent *event)
+void MainWindow::closeEvent ( QCloseEvent *event )
{
// Save the window state and geometry.
// TODO: Make this work with the new settings system.
// settings->getConfig().setValue("MainWindowGeometry", saveGeometry());
// settings->getConfig().setValue("MainWindowState", saveState());
- QMainWindow::closeEvent(event);
+ QMainWindow::closeEvent ( event );
}
-void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos)
+void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos )
{
- QMenu *instContextMenu = new QMenu("Instance", this);
-
+ QMenu *instContextMenu = new QMenu ( "Instance", this );
+
// Add the actions from the toolbar to the context menu.
- instContextMenu->addActions(ui->instanceToolBar->actions());
-
- instContextMenu->exec(ui->instanceView->mapToGlobal(pos));
+ instContextMenu->addActions ( ui->instanceToolBar->actions() );
+
+ instContextMenu->exec ( view->mapToGlobal ( pos ) );
}
void MainWindow::on_actionLaunchInstance_triggered()
{
- doLogin();
+ QModelIndex index = view->currentIndex();
+ if(index.isValid())
+ {
+ Instance * inst = (Instance *) index.data(InstanceModel::InstancePointerRole).value<void *>();
+ doLogin(inst->id());
+ }
}
-void MainWindow::doLogin(const QString &errorMsg)
+void MainWindow::doLogin ( QString inst, const QString& errorMsg )
{
- LoginDialog* loginDlg = new LoginDialog(this, errorMsg);
- if (loginDlg->exec())
+ LoginDialog* loginDlg = new LoginDialog ( this, errorMsg );
+ if ( loginDlg->exec() )
{
- UserInfo uInfo(loginDlg->getUsername(), loginDlg->getPassword());
-
- TaskDialog* tDialog = new TaskDialog(this);
- LoginTask* loginTask = new LoginTask(uInfo, tDialog);
- connect(loginTask, SIGNAL(loginComplete(LoginResponse)),
- SLOT(onLoginComplete(LoginResponse)), Qt::QueuedConnection);
- connect(loginTask, SIGNAL(loginFailed(QString)),
- SLOT(doLogin(QString)), Qt::QueuedConnection);
- tDialog->exec(loginTask);
+ UserInfo uInfo ( loginDlg->getUsername(), loginDlg->getPassword() );
+
+ TaskDialog* tDialog = new TaskDialog ( this );
+ LoginTask* loginTask = new LoginTask ( uInfo, inst, tDialog );
+ connect ( loginTask, SIGNAL ( loginComplete ( QString, LoginResponse ) ),
+ SLOT ( onLoginComplete ( QString, LoginResponse ) ), Qt::QueuedConnection );
+ connect ( loginTask, SIGNAL ( loginFailed ( QString, QString ) ),
+ SLOT ( onLoginFailed( QString, QString ) ), Qt::QueuedConnection );
+ tDialog->exec ( loginTask );
}
}
-void MainWindow::onLoginComplete(LoginResponse response)
+void MainWindow::onLoginComplete ( QString inst, LoginResponse response )
{
- QMessageBox::information(this, "Login Successful",
- QString("Logged in as %1 with session ID %2.").
- arg(response.username(), response.sessionID()));
+ QMessageBox::information ( this, "Login Successful",
+ QString ( "Logged in as %1 with session ID %2. Instance: %3" ).
+ arg ( response.username(), response.sessionID(), inst ) );
}
+void MainWindow::onLoginFailed ( QString inst, const QString& errorMsg )
+{
+ doLogin(inst, errorMsg);
+}
+
+
// Create A Desktop Shortcut
void MainWindow::on_actionMakeDesktopShortcut_triggered()
{
- QString name("Test");
- name = QInputDialog::getText(this, tr("MultiMC Shortcut"), tr("Enter a Shortcut Name."), QLineEdit::Normal, name);
+ QString name ( "Test" );
+ name = QInputDialog::getText ( this, tr ( "MultiMC Shortcut" ), tr ( "Enter a Shortcut Name." ), QLineEdit::Normal, name );
- Util::createShortCut(Util::getDesktopDir(), QApplication::instance()->applicationFilePath(), QStringList() << "-dl" << QDir::currentPath() << "test", name, "application-x-octet-stream");
+ Util::createShortCut ( Util::getDesktopDir(), QApplication::instance()->applicationFilePath(), QStringList() << "-dl" << QDir::currentPath() << "test", name, "application-x-octet-stream" );
- QMessageBox::warning(this, "Not useful", "A Dummy Shortcut was created. it will not do anything productive");
+ QMessageBox::warning ( this, "Not useful", "A Dummy Shortcut was created. it will not do anything productive" );
}
// BrowserDialog
-void MainWindow::openWebPage(QUrl url)
+void MainWindow::openWebPage ( QUrl url )
{
- BrowserDialog *browser = new BrowserDialog(this);
+ BrowserDialog *browser = new BrowserDialog ( this );
- browser->load(url);
- browser->exec();
+ browser->load ( url );
+ browser->exec();
}
-void openInDefaultProgram(QString filename)
+void openInDefaultProgram ( QString filename )
{
- QDesktopServices::openUrl("file:///" + QFileInfo(filename).absolutePath());
+ QDesktopServices::openUrl ( "file:///" + QFileInfo ( filename ).absolutePath() );
}
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 5ea575a6..c2dedf74 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -20,6 +20,12 @@
#include "instancelist.h"
#include "loginresponse.h"
+#include "instance.h"
+
+class InstanceModel;
+class InstanceProxyModel;
+class KCategorizedView;
+class KCategoryDrawer;
namespace Ui
{
@@ -67,14 +73,21 @@ private slots:
void on_actionMakeDesktopShortcut_triggered();
- void doLogin(const QString& errorMsg = "");
-
+ void doLogin( QString inst, const QString& errorMsg = "" );
- void onLoginComplete(LoginResponse response);
+ void onLoginComplete( QString inst, LoginResponse response );
+ void onLoginFailed( QString inst, const QString& errorMsg );
+
+public slots:
+ void instanceActivated ( QModelIndex );
+
private:
Ui::MainWindow *ui;
-
+ KCategoryDrawer * drawer;
+ KCategorizedView * view;
+ InstanceModel * model;
+ InstanceProxyModel * proxymodel;
InstanceList instList;
};
diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui
index 137f7e97..fe6de6c9 100644
--- a/gui/mainwindow.ui
+++ b/gui/mainwindow.ui
@@ -33,22 +33,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
- <item>
- <widget class="QTreeView" name="instanceView">
- <property name="animated">
- <bool>true</bool>
- </property>
- <property name="allColumnsShowFocus">
- <bool>true</bool>
- </property>
- <attribute name="headerVisible">
- <bool>false</bool>
- </attribute>
- <property name="contextMenuPolicy">
- <enum>Qt::CustomContextMenu</enum>
- </property>
- </widget>
- </item>
</layout>
</widget>
<widget class="QToolBar" name="mainToolBar">