Skip to content

Commit

Permalink
GUI: Add status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpm54 authored and DrMcCoy committed May 22, 2018
1 parent 942f5e9 commit b8624db
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <QLabel>
#include <QFileDialog>
#include <QStandardPaths>
#include <QStatusBar>

#include <boost/scope_exit.hpp>

#include "verdigris/wobjectimpl.h"

Expand All @@ -51,7 +54,7 @@ namespace GUI {
W_OBJECT_IMPL(MainWindow)

MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, const char *path) :
QMainWindow(parent), _treeModel(0), _proxyModel(0), _rootPath("") {
QMainWindow(parent), _status(statusBar()), _treeModel(0), _proxyModel(0), _rootPath("") {
/* Window setup. */
setWindowTitle(title);
resize(size);
Expand Down Expand Up @@ -189,6 +192,8 @@ MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, co
_treeModel.reset(new ResourceTree(this, _treeView));
_proxyModel.reset(new ProxyModel(this));

_status.setText("Idle...");

if (qpath.isEmpty())
_actionClose->setEnabled(false);
else
Expand Down Expand Up @@ -222,6 +227,8 @@ void MainWindow::slotClose() {
_rootPath = "";

_actionClose->setEnabled(false);

_status.pop();
}

void MainWindow::slotQuit() {
Expand All @@ -239,9 +246,14 @@ void MainWindow::open(const QString &path) {

_rootPath = path;

// popped in openFinish
_status.push("Populating resource tree...");

try {
_files.readPath(Common::UString(path.toStdString()), -1);
} catch (Common::Exception &e) {
_status.pop();

Common::printException(e, "WARNING: ");
return;
}
Expand All @@ -262,6 +274,16 @@ void MainWindow::openFinish() {
_treeView->expandToDepth(0);
_treeView->show();
_treeView->resizeColumnToContents(0);

_status.pop();
}

void MainWindow::statusPush(const QString &text) {
_status.push(text);
}

void MainWindow::statusPop() {
_status.pop();
}

} // End of namespace GUI
6 changes: 6 additions & 0 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "src/gui/resourcetree.h"
#include "src/gui/proxymodel.h"
#include "src/gui/statusbar.h"

#include "verdigris/wobjectdefs.h"

Expand Down Expand Up @@ -72,6 +73,11 @@ private /*slots*/:
void open(const QString &path);
void openFinish();

void statusPush(const QString &text);
void statusPop();

StatusBar _status;

QWidget *_centralWidget;
QGridLayout *_centralLayout;

Expand Down
10 changes: 10 additions & 0 deletions src/gui/resourcetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ void ResourceTree::fetchMore(const QModelIndex &index) {
if (archive.addedMembers)
return;

_mainWindow->statusPush(tr("Loading archive") + item->getName() + "...");
BOOST_SCOPE_EXIT((&_mainWindow)) {
_mainWindow->statusPop();
} BOOST_SCOPE_EXIT_END

// Load the archive, if necessary
if (!archive.data) {
try {
Expand Down Expand Up @@ -295,10 +300,15 @@ void ResourceTree::loadKEYDataFiles(Aurora::KEYFile &key) {
const std::vector<Common::UString> dataFiles = key.getDataFileList();
for (size_t i = 0; i < dataFiles.size(); i++) {
try {
_mainWindow->statusPush(tr("Loading data file") + QString::fromUtf8(dataFiles[i].c_str()) + "...");

Aurora::KEYDataFile *dataFile = getKEYDataFile(QString::fromUtf8(dataFiles[i].c_str()));
key.addDataFile(i, dataFile);

_mainWindow->statusPop();
} catch (Common::Exception &e) {
e.add("Failed to load KEY data file \"%s\"", dataFiles[i].c_str());
_mainWindow->statusPop();
Common::printException(e, "WARNING: ");
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ src_gui_libgui_la_SOURCES += \
src/gui/resourcetree.h \
src/gui/resourcetreeitem.h \
src/gui/proxymodel.h \
src/gui/statusbar.h \
$(EMPTY)

src_gui_libgui_la_SOURCES += \
src/gui/mainwindow.cpp \
src/gui/resourcetree.cpp \
src/gui/resourcetreeitem.cpp \
src/gui/proxymodel.cpp \
src/gui/statusbar.cpp \
$(EMPTY)
47 changes: 47 additions & 0 deletions src/gui/statusbar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Phaethon - A FLOSS resource explorer for BioWare's Aurora engine games
*
* Phaethon is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* Phaethon 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 3
* of the License, or (at your option) any later version.
*
* Phaethon 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 Phaethon. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Wrapper class for status bar in order to
* have identical functionality to Phaethon (wx version.)
*/

#include "statusbar.h"

namespace GUI {

StatusBar::StatusBar(QStatusBar *statusBar) {
_statusBar = statusBar;
}

void StatusBar::setText(const QString &text) {
_statusBar->showMessage(text);
_text = text;
}

void StatusBar::push(const QString &text, int timeout) {
_statusBar->showMessage(text, timeout);
}

void StatusBar::pop() {
_statusBar->showMessage(_text);
}

} // End of namespace GUI
49 changes: 49 additions & 0 deletions src/gui/statusbar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Phaethon - A FLOSS resource explorer for BioWare's Aurora engine games
*
* Phaethon is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* Phaethon 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 3
* of the License, or (at your option) any later version.
*
* Phaethon 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 Phaethon. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Wrapper class for status bar in order to
* have identical functionality to Phaethon (wx version.)
*/

#ifndef STATUSBAR_H
#define STATUSBAR_H

#include <QMainWindow>
#include <QStatusBar>
#include <QWidget>

namespace GUI {

class StatusBar {
public:
StatusBar(QStatusBar *statusBar);
void setText(const QString &text);
void push(const QString &text, int timeout = 0);
void pop();

private:
QStatusBar *_statusBar;
QString _text;
};

} // End of namespace GUI

#endif // STATUSBAR_H

0 comments on commit b8624db

Please sign in to comment.