From a416c58a93dd9d108f4c4fa968b9431e30834c5c Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 5 Feb 2013 16:34:20 -0600 Subject: [PATCH] Started working on task system and login system. --- CMakeLists.txt | 12 ++++ data/loginresponse.cpp | 49 ++++++++++++++ data/loginresponse.h | 39 +++++++++++ data/userinfo.cpp | 49 ++++++++++++++ data/userinfo.h | 39 +++++++++++ gui/logindialog.cpp | 51 ++++++++++++++ gui/logindialog.h | 40 +++++++++++ gui/logindialog.ui | 146 +++++++++++++++++++++++++++++++++++++++++ gui/mainwindow.cpp | 32 +++++++++ gui/mainwindow.h | 11 +++- gui/taskdialog.cpp | 109 ++++++++++++++++++++++++++++++ gui/taskdialog.h | 63 ++++++++++++++++++ gui/taskdialog.ui | 53 +++++++++++++++ tasks/logintask.cpp | 44 +++++++++++++ tasks/logintask.h | 40 +++++++++++ tasks/task.cpp | 8 +-- tasks/task.h | 7 +- 17 files changed, 784 insertions(+), 8 deletions(-) create mode 100644 data/loginresponse.cpp create mode 100644 data/loginresponse.h create mode 100644 data/userinfo.cpp create mode 100644 data/userinfo.h create mode 100644 gui/logindialog.cpp create mode 100644 gui/logindialog.h create mode 100644 gui/logindialog.ui create mode 100644 gui/taskdialog.cpp create mode 100644 gui/taskdialog.h create mode 100644 gui/taskdialog.ui create mode 100644 tasks/logintask.cpp create mode 100644 tasks/logintask.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 932f70e19..b466924cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,11 +96,15 @@ data/instancebase.cpp data/instancemodel.cpp data/stdinstance.cpp data/version.cpp +data/userinfo.cpp +data/loginresponse.cpp gui/mainwindow.cpp gui/modeditwindow.cpp gui/settingsdialog.cpp gui/newinstancedialog.cpp +gui/logindialog.cpp +gui/taskdialog.cpp util/pathutils.cpp util/osutils.cpp @@ -109,6 +113,7 @@ java/javautils.cpp java/annotations.cpp tasks/task.cpp +tasks/logintask.cpp ) SET(MULTIMC_HEADERS @@ -116,6 +121,8 @@ gui/mainwindow.h gui/modeditwindow.h gui/settingsdialog.h gui/newinstancedialog.h +gui/logindialog.h +gui/taskdialog.h data/appsettings.h data/inifile.h @@ -123,6 +130,8 @@ data/instancebase.h data/instancemodel.h data/stdinstance.h data/version.h +data/userinfo.h +data/loginresponse.h util/apputils.h util/pathutils.h @@ -139,6 +148,7 @@ java/javautils.h java/membuffer.h tasks/task.h +tasks/logintask.h ) SET(MULTIMC5_UIS @@ -146,6 +156,8 @@ gui/mainwindow.ui gui/modeditwindow.ui gui/settingsdialog.ui gui/newinstancedialog.ui +gui/logindialog.ui +gui/taskdialog.ui ) IF(WIN32) diff --git a/data/loginresponse.cpp b/data/loginresponse.cpp new file mode 100644 index 000000000..a36471144 --- /dev/null +++ b/data/loginresponse.cpp @@ -0,0 +1,49 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "loginresponse.h" + +LoginResponse::LoginResponse(const QString& username, const QString& sessionID, QObject *parent) : + QObject(parent) +{ + this->username = username; + this->sessionID = sessionID; +} + +LoginResponse::LoginResponse(const LoginResponse &other) +{ + this->username = other.username; + this->sessionID = other.sessionID; +} + +QString LoginResponse::getUsername() const +{ + return username; +} + +void LoginResponse::setUsername(const QString& username) +{ + this->username = username; +} + +QString LoginResponse::getSessionID() const +{ + return sessionID; +} + +void LoginResponse::setSessionID(const QString& sessionID) +{ + this->sessionID = sessionID; +} diff --git a/data/loginresponse.h b/data/loginresponse.h new file mode 100644 index 000000000..e780750fa --- /dev/null +++ b/data/loginresponse.h @@ -0,0 +1,39 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOGINRESPONSE_H +#define LOGINRESPONSE_H + +#include + +class LoginResponse : public QObject +{ + Q_OBJECT +public: + explicit LoginResponse(const QString &username, const QString &sessionID, QObject *parent = 0); + LoginResponse(const LoginResponse& other); + + QString getUsername() const; + void setUsername(const QString& username); + + QString getSessionID() const; + void setSessionID(const QString& sessionID); + +private: + QString username; + QString sessionID; +}; + +#endif // LOGINRESPONSE_H diff --git a/data/userinfo.cpp b/data/userinfo.cpp new file mode 100644 index 000000000..907f93a27 --- /dev/null +++ b/data/userinfo.cpp @@ -0,0 +1,49 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "userinfo.h" + +UserInfo::UserInfo(const QString &username, const QString &password, QObject *parent) : + QObject(parent) +{ + this->username = username; + this->password = password; +} + +UserInfo::UserInfo(const UserInfo &other) +{ + this->username = other.username; + this->password = other.password; +} + +QString UserInfo::getUsername() const +{ + return username; +} + +void UserInfo::setUsername(const QString &username) +{ + this->username = username; +} + +QString UserInfo::getPassword() const +{ + return password; +} + +void UserInfo::setPassword(const QString &password) +{ + this->password = password; +} diff --git a/data/userinfo.h b/data/userinfo.h new file mode 100644 index 000000000..ccfc741e1 --- /dev/null +++ b/data/userinfo.h @@ -0,0 +1,39 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef USERINFO_H +#define USERINFO_H + +#include + +class UserInfo : public QObject +{ + Q_OBJECT +public: + explicit UserInfo(const QString& username, const QString& password, QObject *parent = 0); + explicit UserInfo(const UserInfo& other); + + QString getUsername() const; + void setUsername(const QString& username); + + QString getPassword() const; + void setPassword(const QString& password); + +protected: + QString username; + QString password; +}; + +#endif // USERINFO_H diff --git a/gui/logindialog.cpp b/gui/logindialog.cpp new file mode 100644 index 000000000..426757a9a --- /dev/null +++ b/gui/logindialog.cpp @@ -0,0 +1,51 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "logindialog.h" +#include "ui_logindialog.h" + +LoginDialog::LoginDialog(QWidget *parent, const QString& loginErrMsg) : + QDialog(parent), + ui(new Ui::LoginDialog) +{ + ui->setupUi(this); + + if (loginErrMsg.isEmpty()) + ui->loginErrorLabel->setVisible(false); + else + { + ui->loginErrorLabel->setVisible(true); + ui->loginErrorLabel->setText(QString("%1"). + arg(loginErrMsg)); + } + + resize(minimumSizeHint()); + layout()->setSizeConstraint(QLayout::SetFixedSize); +} + +LoginDialog::~LoginDialog() +{ + delete ui; +} + +QString LoginDialog::getUsername() const +{ + return ui->usernameTextBox->text(); +} + +QString LoginDialog::getPassword() const +{ + return ui->passwordTextBox->text(); +} diff --git a/gui/logindialog.h b/gui/logindialog.h new file mode 100644 index 000000000..1b70dcd50 --- /dev/null +++ b/gui/logindialog.h @@ -0,0 +1,40 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOGINDIALOG_H +#define LOGINDIALOG_H + +#include + +namespace Ui { +class LoginDialog; +} + +class LoginDialog : public QDialog +{ + Q_OBJECT + +public: + explicit LoginDialog(QWidget *parent = 0, const QString& loginErrMsg = ""); + ~LoginDialog(); + + QString getUsername() const; + QString getPassword() const; + +private: + Ui::LoginDialog *ui; +}; + +#endif // LOGINDIALOG_H diff --git a/gui/logindialog.ui b/gui/logindialog.ui new file mode 100644 index 000000000..ce41d2f52 --- /dev/null +++ b/gui/logindialog.ui @@ -0,0 +1,146 @@ + + + LoginDialog + + + + 0 + 0 + 365 + 145 + + + + Login + + + + + + <span style=" color:#ff0000;">Error</span> + + + + + + + + + Username: + + + + + + + Username + + + + + + + Password: + + + + + + + QLineEdit::Password + + + Password + + + + + + + + + + + &Force Update + + + true + + + + + + + + 1 + 0 + + + + &Remember Username? + + + + + + + + 1 + 0 + + + + R&emember Password? + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + loginButtonBox + accepted() + LoginDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + loginButtonBox + rejected() + LoginDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 1ff633b2f..c2f0c3903 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -26,10 +26,14 @@ #include "gui/settingsdialog.h" #include "gui/newinstancedialog.h" +#include "gui/logindialog.h" +#include "gui/taskdialog.h" #include "data/appsettings.h" #include "data/version.h" +#include "tasks/logintask.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -121,3 +125,31 @@ void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) instContextMenu->exec(ui->instanceView->mapToGlobal(pos)); } + + +void MainWindow::on_actionLaunchInstance_triggered() +{ + doLogin(); +} + +void MainWindow::doLogin(const QString &errorMsg) +{ + 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))); + connect(loginTask, SIGNAL(loginFailed(QString)), + SLOT(doLogin(QString))); + tDialog->exec(loginTask); + } +} + +void MainWindow::onLoginComplete(LoginResponse response) +{ + +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index ce06a085d..28ca341ae 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -18,7 +18,8 @@ #include -#include "../data/instancemodel.h" +#include "data/instancemodel.h" +#include "data/loginresponse.h" namespace Ui { @@ -58,6 +59,14 @@ private slots: void on_instanceView_customContextMenuRequested(const QPoint &pos); + void on_actionLaunchInstance_triggered(); + + + void doLogin(const QString& errorMsg = ""); + + + void onLoginComplete(LoginResponse response); + private: Ui::MainWindow *ui; diff --git a/gui/taskdialog.cpp b/gui/taskdialog.cpp new file mode 100644 index 000000000..a8738fe3d --- /dev/null +++ b/gui/taskdialog.cpp @@ -0,0 +1,109 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "taskdialog.h" +#include "ui_taskdialog.h" + +#include + +#include "tasks/task.h" + +TaskDialog::TaskDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::TaskDialog) +{ + ui->setupUi(this); + updateSize(); + + changeProgress(0); +} + +TaskDialog::~TaskDialog() +{ + delete ui; +} + +void TaskDialog::updateSize() +{ + resize(QSize(480, minimumSizeHint().height())); +} + +void TaskDialog::exec(Task *task) +{ + this->task = task; + + // Connect signals. + connect(task, SIGNAL(taskStarted(Task*)), + this, SLOT(onTaskStarted(Task*))); + connect(task, SIGNAL(taskEnded(Task*)), + this, SLOT(onTaskEnded(Task*))); + connect(task, SIGNAL(statusChanged(const QString&)), + this, SLOT(changeStatus(const QString&))); + connect(task, SIGNAL(progressChanged(int)), + this, SLOT(changeProgress(int))); + + task->startTask(); + QDialog::exec(); +} + +Task* TaskDialog::getTask() +{ + return task; +} + +void TaskDialog::onTaskStarted(Task*) +{ + +} + +void TaskDialog::onTaskEnded(Task*) +{ + close(); +} + +void TaskDialog::changeStatus(const QString &status) +{ + ui->statusLabel->setText(status); + updateSize(); +} + +void TaskDialog::changeProgress(int progress) +{ + if (progress < 0) + progress = 0; + else if (progress > 100) + progress = 100; + + ui->taskProgressBar->setValue(progress); +} + +void TaskDialog::keyPressEvent(QKeyEvent* e) +{ + if (e->key() == Qt::Key_Escape) + return; + QDialog::keyPressEvent(e); +} + +void TaskDialog::closeEvent(QCloseEvent* e) +{ + if (task && task->isRunning()) + { + e->ignore(); + } + else + { + QDialog::closeEvent(e); + } +} diff --git a/gui/taskdialog.h b/gui/taskdialog.h new file mode 100644 index 000000000..faf3ed90c --- /dev/null +++ b/gui/taskdialog.h @@ -0,0 +1,63 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TASKDIALOG_H +#define TASKDIALOG_H + +#include + +class Task; + +namespace Ui { +class TaskDialog; +} + +class TaskDialog : public QDialog +{ + Q_OBJECT + +public: + explicit TaskDialog(QWidget *parent = 0); + ~TaskDialog(); + + void updateSize(); + + void exec(Task* task); + + Task* getTask(); + +public slots: + void onTaskStarted(Task*); + void onTaskEnded(Task*); + + void changeStatus(const QString& status); + void changeProgress(int progress); + + void test() { qDebug("Lol"); } + +signals: + + +protected: + virtual void keyPressEvent(QKeyEvent* e); + virtual void closeEvent(QCloseEvent* e); + +private: + Ui::TaskDialog *ui; + + Task* task; +}; + +#endif // TASKDIALOG_H diff --git a/gui/taskdialog.ui b/gui/taskdialog.ui new file mode 100644 index 000000000..1cdf79785 --- /dev/null +++ b/gui/taskdialog.ui @@ -0,0 +1,53 @@ + + + TaskDialog + + + + 0 + 0 + 400 + 58 + + + + + 400 + 0 + + + + + 600 + 16777215 + + + + Please wait... + + + + + + Task Status... + + + true + + + + + + + 24 + + + false + + + + + + + + diff --git a/tasks/logintask.cpp b/tasks/logintask.cpp new file mode 100644 index 000000000..211e1c17a --- /dev/null +++ b/tasks/logintask.cpp @@ -0,0 +1,44 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "logintask.h" + +LoginTask::LoginTask(const UserInfo &uInfo, QObject *parent) : + Task(parent), uInfo(uInfo) +{ + +} + +void LoginTask::executeTask() +{ + setStatus("Logging in..."); + + // TODO: PLACEHOLDER + for (int p = 0; p < 100; p++) + { + msleep(25); + setProgress(p); + } + + if (uInfo.getUsername() == "test") + { + LoginResponse response("test", "Fake Session ID"); + emit loginComplete(response); + } + else + { + emit loginFailed("Testing"); + } +} diff --git a/tasks/logintask.h b/tasks/logintask.h new file mode 100644 index 000000000..93aab9b3b --- /dev/null +++ b/tasks/logintask.h @@ -0,0 +1,40 @@ +/* Copyright 2013 MultiMC Contributors + * + * 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 + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOGINTASK_H +#define LOGINTASK_H + +#include "task.h" + +#include "data/userinfo.h" +#include "data/loginresponse.h" + +class LoginTask : public Task +{ + Q_OBJECT +public: + explicit LoginTask(const UserInfo& uInfo, QObject *parent = 0); + +signals: + void loginComplete(const LoginResponse& loginResponse); + void loginFailed(const QString& errorMsg); + +protected: + void executeTask(); + + UserInfo uInfo; +}; + +#endif // LOGINTASK_H diff --git a/tasks/task.cpp b/tasks/task.cpp index 8d65b415c..d581a1dde 100644 --- a/tasks/task.cpp +++ b/tasks/task.cpp @@ -29,7 +29,7 @@ QString Task::getStatus() const void Task::setStatus(const QString &status) { this->status = status; - statusChanged(status); + emit statusChanged(status); } int Task::getProgress() const @@ -40,7 +40,7 @@ int Task::getProgress() const void Task::setProgress(int progress) { this->progress = progress; - progressChanged(progress); + emit progressChanged(progress); } void Task::startTask() @@ -50,7 +50,7 @@ void Task::startTask() void Task::run() { - taskStarted(this); + emit taskStarted(this); executeTask(); - taskEnded(this); + emit taskEnded(this); } diff --git a/tasks/task.h b/tasks/task.h index 714889c8e..0124d8cfb 100644 --- a/tasks/task.h +++ b/tasks/task.h @@ -32,6 +32,10 @@ public: QString getStatus() const; int getProgress() const; +public slots: + void setStatus(const QString& status); + void setProgress(int progress); + signals: void taskStarted(Task* task); void taskEnded(Task* task); @@ -40,9 +44,6 @@ signals: void progressChanged(int progress); protected: - void setStatus(const QString& status); - void setProgress(int progress); - virtual void run(); virtual void executeTask() = 0;