summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/consolewindow.cpp77
-rw-r--r--gui/consolewindow.h79
-rw-r--r--gui/iconcache.cpp127
-rw-r--r--gui/iconcache.h43
-rw-r--r--gui/instancedelegate.cpp12
-rw-r--r--gui/instancemodel.cpp43
-rw-r--r--gui/instancemodel.h7
-rw-r--r--gui/logindialog.cpp51
-rw-r--r--gui/logindialog.h6
-rw-r--r--gui/logindialog.ui33
-rw-r--r--gui/mainwindow.cpp86
-rw-r--r--gui/mainwindow.h11
-rw-r--r--gui/settingsdialog.ui44
13 files changed, 482 insertions, 137 deletions
diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp
index 1d84fe04..811900a2 100644
--- a/gui/consolewindow.cpp
+++ b/gui/consolewindow.cpp
@@ -4,70 +4,71 @@
#include <QScrollBar>
ConsoleWindow::ConsoleWindow(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::ConsoleWindow),
- m_mayclose(true)
+ QDialog(parent),
+ ui(new Ui::ConsoleWindow),
+ m_mayclose(true)
{
- ui->setupUi(this);
+ ui->setupUi(this);
}
ConsoleWindow::~ConsoleWindow()
{
- delete ui;
+ delete ui;
}
void ConsoleWindow::writeColor(QString text, const char *color)
{
- // append a paragraph
- if (color != nullptr)
- ui->text->appendHtml(QString("<font color=%1>%2</font>").arg(color).arg(text));
- else
- ui->text->appendPlainText(text);
- // scroll down
- QScrollBar *bar = ui->text->verticalScrollBar();
- bar->setValue(bar->maximum());
+ // append a paragraph
+ if (color != nullptr)
+ ui->text->appendHtml(QString("<font color=%1>%2</font>").arg(color).arg(text));
+ else
+ ui->text->appendPlainText(text);
+ // scroll down
+ QScrollBar *bar = ui->text->verticalScrollBar();
+ bar->setValue(bar->maximum());
}
-void ConsoleWindow::write(QString data, WriteMode mode)
+void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
{
- if (data.endsWith('\n'))
- data = data.left(data.length()-1);
- QStringList paragraphs = data.split('\n');
- QListIterator<QString> iter(paragraphs);
- if (mode == MULTIMC)
- while(iter.hasNext())
- writeColor(iter.next(), "blue");
- else if (mode == ERROR)
- while(iter.hasNext())
- writeColor(iter.next(), "red");
- else
- while(iter.hasNext())
- writeColor(iter.next());
+ if (data.endsWith('\n'))
+ data = data.left(data.length()-1);
+ QStringList paragraphs = data.split('\n');
+ QListIterator<QString> iter(paragraphs);
+ if (mode == MessageLevel::MultiMC)
+ while(iter.hasNext())
+ writeColor(iter.next(), "blue");
+ else if (mode == MessageLevel::Error)
+ while(iter.hasNext())
+ writeColor(iter.next(), "red");
+ // TODO: implement other MessageLevels
+ else
+ while(iter.hasNext())
+ writeColor(iter.next());
}
void ConsoleWindow::clear()
{
- ui->text->clear();
+ ui->text->clear();
}
void ConsoleWindow::on_closeButton_clicked()
{
- close();
+ close();
}
void ConsoleWindow::setMayClose(bool mayclose)
{
- m_mayclose = mayclose;
- if (mayclose)
- ui->closeButton->setEnabled(true);
- else
- ui->closeButton->setEnabled(false);
+ m_mayclose = mayclose;
+ if (mayclose)
+ ui->closeButton->setEnabled(true);
+ else
+ ui->closeButton->setEnabled(false);
}
void ConsoleWindow::closeEvent(QCloseEvent * event)
{
- if(!m_mayclose)
- event->ignore();
- else
- QDialog::closeEvent(event);
+ if(!m_mayclose)
+ event->ignore();
+ else
+ QDialog::closeEvent(event);
}
diff --git a/gui/consolewindow.h b/gui/consolewindow.h
index 1d322afb..5490bc92 100644
--- a/gui/consolewindow.h
+++ b/gui/consolewindow.h
@@ -2,6 +2,7 @@
#define CONSOLEWINDOW_H
#include <QDialog>
+#include "minecraftprocess.h"
namespace Ui {
class ConsoleWindow;
@@ -9,61 +10,51 @@ class ConsoleWindow;
class ConsoleWindow : public QDialog
{
- Q_OBJECT
+ Q_OBJECT
public:
- /**
- * @brief The WriteMode enum
- * defines how stuff is displayed
- */
- enum WriteMode {
- DEFAULT,
- ERROR,
- MULTIMC
- };
+ explicit ConsoleWindow(QWidget *parent = 0);
+ ~ConsoleWindow();
- explicit ConsoleWindow(QWidget *parent = 0);
- ~ConsoleWindow();
-
- /**
- * @brief specify if the window is allowed to close
- * @param mayclose
- * used to keep it alive while MC runs
- */
- void setMayClose(bool mayclose);
+ /**
+ * @brief specify if the window is allowed to close
+ * @param mayclose
+ * used to keep it alive while MC runs
+ */
+ void setMayClose(bool mayclose);
public slots:
- /**
- * @brief write a string
- * @param data the string
- * @param mode the WriteMode
- * lines have to be put through this as a whole!
- */
- void write(QString data, WriteMode mode=MULTIMC);
-
- /**
- * @brief write a colored paragraph
- * @param data the string
- * @param color the css color name
- * this will only insert a single paragraph.
- * \n are ignored. a real \n is always appended.
- */
- void writeColor(QString data, const char *color=nullptr);
-
- /**
- * @brief clear the text widget
- */
- void clear();
+ /**
+ * @brief write a string
+ * @param data the string
+ * @param mode the WriteMode
+ * lines have to be put through this as a whole!
+ */
+ void write(QString data, MessageLevel::Enum level=MessageLevel::MultiMC);
+
+ /**
+ * @brief write a colored paragraph
+ * @param data the string
+ * @param color the css color name
+ * this will only insert a single paragraph.
+ * \n are ignored. a real \n is always appended.
+ */
+ void writeColor(QString data, const char *color=nullptr);
+
+ /**
+ * @brief clear the text widget
+ */
+ void clear();
private slots:
- void on_closeButton_clicked();
+ void on_closeButton_clicked();
protected:
- void closeEvent(QCloseEvent *);
+ void closeEvent(QCloseEvent *);
private:
- Ui::ConsoleWindow *ui;
- bool m_mayclose;
+ Ui::ConsoleWindow *ui;
+ bool m_mayclose;
};
#endif // CONSOLEWINDOW_H
diff --git a/gui/iconcache.cpp b/gui/iconcache.cpp
new file mode 100644
index 00000000..520a7839
--- /dev/null
+++ b/gui/iconcache.cpp
@@ -0,0 +1,127 @@
+#include "iconcache.h"
+#include <QMap>
+#include <QWebView>
+#include <QWebFrame>
+#include <QEventLoop>
+#include <QWebElement>
+
+IconCache* IconCache::m_Instance = 0;
+QMutex IconCache::mutex;
+#define MAX_SIZE 1024
+
+class Private : public QWebView
+{
+ Q_OBJECT
+
+public:
+ QString name;
+ QSize size;
+ QMap<QString, QIcon> icons;
+
+public:
+ Private()
+ {
+ connect(this, SIGNAL(loadFinished(bool)), this, SLOT(svgLoaded(bool)));
+ setFixedSize(MAX_SIZE, MAX_SIZE);
+
+ QPalette pal = palette();
+ pal.setColor(QPalette::Base, Qt::transparent);
+ setPalette(pal);
+ setAttribute(Qt::WA_OpaquePaintEvent, false);
+ size = QSize(128,128);
+ }
+ void renderSVGIcon(QString name);
+
+signals:
+ void svgRendered();
+
+private slots:
+ void svgLoaded(bool ok);
+};
+
+void Private::svgLoaded(bool ok)
+{
+ if (!ok)
+ {
+ emit svgRendered();
+ return;
+ }
+ // check for SVG root tag
+ QString root = page()->currentFrame()->documentElement().tagName();
+ if (root.compare("svg", Qt::CaseInsensitive) != 0)
+ {
+ emit svgRendered();
+ return;
+ }
+
+ // get the size of the svg image, check if it's valid
+ auto elem = page()->currentFrame()->documentElement();
+ double width = elem.attribute("width").toDouble();
+ double height = elem.attribute("height").toDouble();
+ if (width == 0.0 || height == 0.0 || width == MAX_SIZE || height == MAX_SIZE)
+ {
+ emit svgRendered();
+ return;
+ }
+
+ // create the target surface
+ QSize t = size.isValid() ? size : QSize(width, height);
+ QImage img(t, QImage::Format_ARGB32_Premultiplied);
+ img.fill(Qt::transparent);
+
+ // prepare the painter, scale to required size
+ QPainter p(&img);
+ if(size.isValid())
+ {
+ p.scale(size.width() / width, size.height() / height);
+ }
+
+ // the best quality
+ p.setRenderHint(QPainter::Antialiasing);
+ p.setRenderHint(QPainter::TextAntialiasing);
+ p.setRenderHint(QPainter::SmoothPixmapTransform);
+
+ page()->mainFrame()->render(&p,QWebFrame::ContentsLayer);
+ p.end();
+
+ icons[name] = QIcon(QPixmap::fromImage(img));
+ emit svgRendered();
+}
+
+void Private::renderSVGIcon ( QString name )
+{
+ // use event loop to wait for signal
+ QEventLoop loop;
+ this->name = name;
+ QString prefix = "qrc:/icons/instances/";
+ QObject::connect(this, SIGNAL(svgRendered()), &loop, SLOT(quit()));
+ load(QUrl(prefix + name));
+ loop.exec();
+}
+
+IconCache::IconCache():d(new Private())
+{
+}
+
+QIcon IconCache::getIcon ( QString name )
+{
+ if(name == "default")
+ name = "infinity";
+ {
+ auto iter = d->icons.find(name);
+ if(iter != d->icons.end())
+ return *iter;
+ }
+ d->renderSVGIcon(name);
+ auto iter = d->icons.find(name);
+ if(iter != d->icons.end())
+ return *iter;
+
+ // Fallback for icons that don't exist.
+ QString path = ":/icons/instances/infinity";
+ //path += name;
+ d->icons[name] = QIcon(path);
+ return d->icons[name];
+}
+
+#include "iconcache.moc" \ No newline at end of file
diff --git a/gui/iconcache.h b/gui/iconcache.h
new file mode 100644
index 00000000..5c5e4142
--- /dev/null
+++ b/gui/iconcache.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <QMutex>
+#include <QtGui/QIcon>
+
+class Private;
+
+class IconCache
+{
+public:
+ static IconCache* instance()
+ {
+ if (!m_Instance)
+ {
+ mutex.lock();
+ if (!m_Instance)
+ m_Instance = new IconCache;
+ mutex.unlock();
+ }
+ return m_Instance;
+ }
+
+ static void drop()
+ {
+ mutex.lock();
+ delete m_Instance;
+ m_Instance = 0;
+ mutex.unlock();
+ }
+
+ QIcon getIcon(QString name);
+
+private:
+ IconCache();
+ // hide copy constructor
+ IconCache(const IconCache &);
+ // hide assign op
+ IconCache& operator=(const IconCache &);
+ static IconCache* m_Instance;
+ static QMutex mutex;
+ Private* d;
+};
+ \ No newline at end of file
diff --git a/gui/instancedelegate.cpp b/gui/instancedelegate.cpp
index dac2dacb..86b7d399 100644
--- a/gui/instancedelegate.cpp
+++ b/gui/instancedelegate.cpp
@@ -33,9 +33,15 @@ ListViewDelegate::ListViewDelegate ( QObject* parent ) : QStyledItemDelegate ( p
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 ) );
+ if ((option.state & QStyle::State_Selected))
+ painter->fillRect ( rect, option.palette.brush ( QPalette::Highlight ) );
+ else
+ {
+ QColor backgroundColor = option.palette.color(QPalette::Background);
+ backgroundColor.setAlpha(160);
+ painter->fillRect ( rect, QBrush(backgroundColor) );
+ }
+
}
void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect)
diff --git a/gui/instancemodel.cpp b/gui/instancemodel.cpp
index 73d0dbc1..8db985e8 100644
--- a/gui/instancemodel.cpp
+++ b/gui/instancemodel.cpp
@@ -1,13 +1,38 @@
#include "instancemodel.h"
#include <instance.h>
#include <QIcon>
+#include "iconcache.h"
InstanceModel::InstanceModel ( const InstanceList& instances, QObject *parent )
: QAbstractListModel ( parent ), m_instances ( &instances )
{
- cachedIcon = QIcon(":/icons/multimc/scalable/apps/multimc.svg");
+ currentInstancesNumber = m_instances->count();
+ connect(m_instances,SIGNAL(instanceAdded(int)),this,SLOT(onInstanceAdded(int)));
+ connect(m_instances,SIGNAL(instanceChanged(int)),this,SLOT(onInstanceChanged(int)));
+ connect(m_instances,SIGNAL(invalidated()),this,SLOT(onInvalidated()));
}
+void InstanceModel::onInstanceAdded ( int index )
+{
+ beginInsertRows(QModelIndex(), index, index);
+ currentInstancesNumber ++;
+ endInsertRows();
+}
+
+void InstanceModel::onInstanceChanged ( int index )
+{
+ QModelIndex mx = InstanceModel::index(index);
+ dataChanged(mx,mx);
+}
+
+void InstanceModel::onInvalidated()
+{
+ beginResetModel();
+ currentInstancesNumber = m_instances->count();
+ endResetModel();
+}
+
+
int InstanceModel::rowCount ( const QModelIndex& parent ) const
{
Q_UNUSED ( parent );
@@ -17,7 +42,7 @@ int InstanceModel::rowCount ( const QModelIndex& parent ) const
QModelIndex InstanceModel::index ( int row, int column, const QModelIndex& parent ) const
{
Q_UNUSED ( parent );
- if ( row < 0 || row >= m_instances->count() )
+ if ( row < 0 || row >= currentInstancesNumber )
return QModelIndex();
return createIndex ( row, column, ( void* ) m_instances->at ( row ).data() );
}
@@ -46,14 +71,22 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
}
case Qt::DecorationRole:
{
- // FIXME: replace with an icon cache
- return cachedIcon;
+ IconCache * ic = IconCache::instance();
+ // FIXME: replace with an icon cache/renderer
+ /*
+ QString path = ":/icons/instances/";
+ path += pdata->iconKey();
+ QIcon icon(path);
+ */
+ QString key = pdata->iconKey();
+ return ic->getIcon(key);
+ //else return QIcon(":/icons/multimc/scalable/apps/multimc.svg");
}
// for now.
case KCategorizedSortFilterProxyModel::CategorySortRole:
case KCategorizedSortFilterProxyModel::CategoryDisplayRole:
{
- return "IT'S A GROUP";
+ return pdata->group();
}
default:
break;
diff --git a/gui/instancemodel.h b/gui/instancemodel.h
index 995c51ec..208ee68e 100644
--- a/gui/instancemodel.h
+++ b/gui/instancemodel.h
@@ -22,9 +22,14 @@ public:
QVariant data ( const QModelIndex& index, int role ) const;
Qt::ItemFlags flags ( const QModelIndex& index ) const;
+public slots:
+ void onInstanceAdded(int index);
+ void onInstanceChanged(int index);
+ void onInvalidated();
+
private:
const InstanceList* m_instances;
- QIcon cachedIcon;
+ int currentInstancesNumber;
};
class InstanceProxyModel : public KCategorizedSortFilterProxyModel
diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp
index 426757a9..842a4541 100644
--- a/gui/logindialog.cpp
+++ b/gui/logindialog.cpp
@@ -15,12 +15,18 @@
#include "logindialog.h"
#include "ui_logindialog.h"
+#include "keyring.h"
LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) :
QDialog(parent),
ui(new Ui::LoginDialog)
{
ui->setupUi(this);
+ //FIXME: translateable?
+ ui->usernameTextBox->lineEdit()->setPlaceholderText(QApplication::translate("LoginDialog", "Name", 0));
+
+ connect(ui->usernameTextBox, SIGNAL(currentTextChanged(QString)), this, SLOT(userTextChanged(QString)));
+ connect(ui->forgetButton, SIGNAL(clicked(bool)), this, SLOT(forgetCurrentUser()));
if (loginErrMsg.isEmpty())
ui->loginErrorLabel->setVisible(false);
@@ -33,6 +39,10 @@ LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) :
resize(minimumSizeHint());
layout()->setSizeConstraint(QLayout::SetFixedSize);
+ Keyring * k = Keyring::instance();
+ QStringList accounts = k->getStoredAccounts("minecraft");
+ ui->usernameTextBox->addItems(accounts);
+
}
LoginDialog::~LoginDialog()
@@ -42,10 +52,49 @@ LoginDialog::~LoginDialog()
QString LoginDialog::getUsername() const
{
- return ui->usernameTextBox->text();
+ return ui->usernameTextBox->currentText();
}
QString LoginDialog::getPassword() const
{
return ui->passwordTextBox->text();
}
+
+void LoginDialog::forgetCurrentUser()
+{
+ Keyring * k = Keyring::instance();
+ QString acct = ui->usernameTextBox->currentText();
+ k->removeStoredAccount("minecraft", acct);
+ ui->passwordTextBox->clear();
+ int index = ui->usernameTextBox->findText(acct);
+ if(index != -1)
+ ui->usernameTextBox->removeItem(index);
+}
+
+void LoginDialog::userTextChanged ( const QString& user )
+{
+ Keyring * k = Keyring::instance();
+ QString acct = ui->usernameTextBox->currentText();
+ QString passwd = k->getPassword("minecraft",acct);
+ ui->passwordTextBox->setText(passwd);
+}
+
+
+void LoginDialog::accept()
+{
+ bool saveName = ui->rememberUsernameCheckbox->isChecked();
+ bool savePass = ui->rememberPasswordCheckbox->isChecked();
+ if(saveName)
+ {
+ Keyring * k = Keyring::instance();
+ if(savePass)
+ {
+ k->storePassword("minecraft",getUsername(),getPassword());
+ }
+ else
+ {
+ k->storePassword("minecraft",getUsername(),QString());
+ }
+ }
+ QDialog::accept();
+}
diff --git a/gui/logindialog.h b/gui/logindialog.h
index 1b70dcd5..5f4410f5 100644
--- a/gui/logindialog.h
+++ b/gui/logindialog.h
@@ -32,7 +32,11 @@ public:
QString getUsername() const;
QString getPassword() const;
-
+
+public slots:
+ virtual void accept();
+ virtual void userTextChanged(const QString& user);
+ virtual void forgetCurrentUser();
private:
Ui::LoginDialog *ui;
};
diff --git a/gui/logindialog.ui b/gui/logindialog.ui
index ce41d2f5..0aaad52b 100644
--- a/gui/logindialog.ui
+++ b/gui/logindialog.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>365</width>
- <height>145</height>
+ <width>476</width>
+ <height>168</height>
</rect>
</property>
<property name="windowTitle">
@@ -31,9 +31,9 @@
</widget>
</item>
<item row="0" column="1">
- <widget class="QLineEdit" name="usernameTextBox">
- <property name="placeholderText">
- <string>Username</string>
+ <widget class="QComboBox" name="usernameTextBox">
+ <property name="editable">
+ <bool>true</bool>
</property>
</widget>
</item>
@@ -54,20 +54,23 @@
</property>
</widget>
</item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="checkboxLayout">
- <item>
- <widget class="QPushButton" name="forceUpdateButton">
- <property name="text">
- <string>&amp;Force Update</string>
+ <item row="0" column="2" rowspan="2">
+ <widget class="QPushButton" name="forgetButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
- <property name="checkable">
- <bool>true</bool>
+ <property name="text">
+ <string>Forget</string>
</property>
</widget>
</item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="checkboxLayout">
<item>
<widget class="QCheckBox" name="rememberUsernameCheckbox">
<property name="sizePolicy">
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index ca681098..7761afe8 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -40,6 +40,7 @@
#include "gui/browserdialog.h"
#include "gui/aboutdialog.h"
#include "gui/versionselectdialog.h"
+#include "gui/consolewindow.h"
#include "kcategorizedview.h"
#include "kcategorydrawer.h"
@@ -50,6 +51,7 @@
#include "logintask.h"
#include <instance.h>
+#include "minecraftprocess.h"
#include "instancemodel.h"
#include "instancedelegate.h"
@@ -65,11 +67,25 @@ MainWindow::MainWindow ( QWidget *parent ) :
{
ui->setupUi ( this );
// Create the widget
- instList.loadList();
-
view = new KCategorizedView ( ui->centralWidget );
drawer = new KCategoryDrawer ( view );
-
+ /*
+ QPalette pal = view->palette();
+ pal.setBrush(QPalette::Base, QBrush(QPixmap(QString::fromUtf8(":/backgrounds/kitteh"))));
+ view->setPalette(pal);
+ */
+ /*
+ view->setStyleSheet(
+ "QListView\
+ {\
+ background-image: url(:/backgrounds/kitteh);\
+ background-attachment: fixed;\
+ background-clip: padding;\
+ background-position: top right;\
+ background-repeat: none;\
+ background-color:palette(base);\
+ }");
+ */
view->setSelectionMode ( QAbstractItemView::SingleSelection );
//view->setSpacing( KDialog::spacingHint() );
view->setCategoryDrawer ( drawer );
@@ -82,6 +98,7 @@ MainWindow::MainWindow ( QWidget *parent ) :
auto delegate = new ListViewDelegate();
view->setItemDelegate(delegate);
view->setSpacing(10);
+ view->setUniformItemWidths(true);
model = new InstanceModel ( instList,this );
proxymodel = new InstanceProxyModel ( this );
@@ -101,7 +118,14 @@ MainWindow::MainWindow ( QWidget *parent ) :
view->setModel ( proxymodel );
connect(view, SIGNAL(doubleClicked(const QModelIndex &)),
this, SLOT(instanceActivated(const QModelIndex &)));
-
+
+ // Load the instances.
+ instList.loadList();
+ // just a test
+ /*
+ instList.at(0)->setGroup("TEST GROUP");
+ instList.at(0)->setName("TEST ITEM");
+ */
}
MainWindow::~MainWindow()
@@ -126,6 +150,18 @@ void MainWindow::on_actionAddInstance_triggered()
newInstDlg->exec();
}
+void MainWindow::on_actionChangeInstGroup_triggered()
+{
+ Instance* inst = selectedInstance();
+ if(inst)
+ {
+ QString name ( inst->group() );
+ name = QInputDialog::getText ( this, tr ( "Group name" ), tr ( "Enter a new group name." ), QLineEdit::Normal, name );
+ inst->setGroup(name);
+ }
+}
+
+
void MainWindow::on_actionViewInstanceFolder_triggered()
{
openInDefaultProgram ( globalSettings->get ( "InstanceDir" ).toString() );
@@ -196,13 +232,31 @@ void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos
instContextMenu->exec ( view->mapToGlobal ( pos ) );
}
+Instance* MainWindow::selectedInstance()
+{
+ QAbstractItemView * iv = view;
+ auto smodel = iv->selectionModel();
+ QModelIndex mindex;
+ if(smodel->hasSelection())
+ {
+ auto rows = smodel->selectedRows();
+ mindex = rows.at(0);
+ }
+
+ if(mindex.isValid())
+ {
+ return (Instance *) mindex.data(InstanceModel::InstancePointerRole).value<void *>();
+ }
+ else
+ return nullptr;
+}
+
void MainWindow::on_actionLaunchInstance_triggered()
{
- QModelIndex index = view->currentIndex();
- if(index.isValid())
+ Instance* inst = selectedInstance();
+ if(inst)
{
- Instance * inst = (Instance *) index.data(InstanceModel::InstancePointerRole).value<void *>();
doLogin(inst->id());
}
}
@@ -226,9 +280,27 @@ void MainWindow::doLogin ( QString inst, const QString& errorMsg )
void MainWindow::onLoginComplete ( QString inst, LoginResponse response )
{
+ // TODO: console
+ console = new ConsoleWindow();
+ auto instance = instList.getInstanceById(inst);
+ if(instance)
+ {
+ proc = new MinecraftProcess(instance, response.username(), response.sessionID());
+
+ console->show();
+ //connect(proc, SIGNAL(ended()), SLOT(onTerminated()));
+ connect(proc, SIGNAL(log(QString,MessageLevel::Enum)), console, SLOT(write(QString,MessageLevel::Enum)));
+ proc->launch();
+ }
+ else
+ {
+
+ }
+ /*
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 )
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 53df9f02..896fe9f1 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -26,6 +26,8 @@ class InstanceModel;
class InstanceProxyModel;
class KCategorizedView;
class KCategoryDrawer;
+class MinecraftProcess;
+class ConsoleWindow;
namespace Ui
{
@@ -44,14 +46,19 @@ public:
// Browser Dialog
void openWebPage(QUrl url);
+
+private:
+ Instance *selectedInstance();
private slots:
void on_actionAbout_triggered();
void on_actionAddInstance_triggered();
- void on_actionViewInstanceFolder_triggered();
+ void on_actionChangeInstGroup_triggered();
+ void on_actionViewInstanceFolder_triggered();
+
void on_actionRefresh_triggered();
void on_actionViewCentralModsFolder_triggered();
@@ -91,6 +98,8 @@ private:
InstanceModel * model;
InstanceProxyModel * proxymodel;
InstanceList instList;
+ MinecraftProcess *proc;
+ ConsoleWindow *console;
};
#endif // MAINWINDOW_H
diff --git a/gui/settingsdialog.ui b/gui/settingsdialog.ui
index d30f56bb..6e6d115f 100644
--- a/gui/settingsdialog.ui
+++ b/gui/settingsdialog.ui
@@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>420</height>
+ <width>453</width>
+ <height>563</height>
</rect>
</property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="windowTitle">
<string>Settings</string>
</property>
@@ -400,31 +406,27 @@
<item row="1" column="1">
<widget class="QLineEdit" name="postExitCmdTextBox"/>
</item>
- <item row="2" column="0" colspan="2">
- <widget class="QLabel" name="labelCustomCmdsDescription">
- <property name="text">
- <string>Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working directory with INST_ID, INST_DIR, and INST_NAME as environment variables.</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
</layout>
</widget>
</item>
<item>
- <spacer name="verticalSpacerJava">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
+ <widget class="QLabel" name="labelCustomCmdsDescription">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
+ <property name="text">
+ <string>Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working directory with INST_ID, INST_DIR, and INST_NAME as environment variables.</string>
</property>
- </spacer>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
</layout>
</widget>