Skip to content

Commit

Permalink
GUI: Remove QString functions from util and ustring
Browse files Browse the repository at this point in the history
This means we have to convert to std::string/c_str but I think it's better this way.
Also don't set the _rootPath in the main window constructor, because it's set in setTreeViewModel anyway.
  • Loading branch information
fdde authored and DrMcCoy committed Dec 29, 2017
1 parent 347279d commit 072ce9e
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 106 deletions.
19 changes: 0 additions & 19 deletions src/aurora/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,6 @@ FileType FileTypeManager::getFileType(const Common::UString &path) {
return kFileTypeNone;
}

FileType FileTypeManager::getFileType(const QString &path) {
buildExtensionLookup();

QString ext = QFileInfo(path).completeSuffix();

ExtensionLookup::const_iterator t = _extensionLookup.find(
Common::UString(
QString(ext).prepend(".").toStdString()
));
if (t != _extensionLookup.end())
return t->second->type;

return kFileTypeNone;
}

Common::UString FileTypeManager::addFileType(const Common::UString &path, FileType type) {
return setFileType(path + ".", type);
}
Expand Down Expand Up @@ -496,10 +481,6 @@ ResourceType FileTypeManager::getResourceType(const Common::UString &path) {
return getResourceType(getFileType(path));
}

ResourceType FileTypeManager::getResourceType(const QString &path) {
return getResourceType(getFileType(path));
}

ResourceType FileTypeManager::getResourceType(Common::HashAlgo algo, uint64 hashedExtension) {
return getResourceType(getFileType(algo, hashedExtension));
}
Expand Down
5 changes: 0 additions & 5 deletions src/aurora/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class FileTypeManager : public Common::Singleton<FileTypeManager> {
/** Return the file type of a file name, detected by its extension. */
FileType getFileType(const Common::UString &path);

/** QString variant */
FileType getFileType(const QString &path);

/** Return the file type of a file name, detected by its hashed extension. */
FileType getFileType(Common::HashAlgo algo, uint64 hashedExtension);

Expand All @@ -69,8 +66,6 @@ class FileTypeManager : public Common::Singleton<FileTypeManager> {
ResourceType getResourceType(FileType type);
/** Return the resource type of a file name, detected by its extension. */
ResourceType getResourceType(const Common::UString &path);
/** QString variant. */
ResourceType getResourceType(const QString &path);
/** Return the resource type of a file name, detected by its hashed extension. */
ResourceType getResourceType(Common::HashAlgo algo, uint64 hashedExtension);

Expand Down
34 changes: 0 additions & 34 deletions src/common/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ UString::UString(const UString &str) {
*this = str;
}

UString::UString(const QString &str) {
*this = str;
}

UString::UString(const std::string &str) {
*this = str;
}
Expand All @@ -68,25 +64,13 @@ UString::UString(iterator sBegin, iterator sEnd) : _size(0) {
UString::~UString() {
}

UString::operator QString() const {
return QString(c_str());
}

UString &UString::operator=(const UString &str) {
_string = str._string;
_size = str._size;

return *this;
}

UString &UString::operator=(const QString &str) {
_string = str.toStdString();

recalculateSize();

return *this;
}

UString &UString::operator=(const std::string &str) {
_string = str;

Expand Down Expand Up @@ -125,14 +109,6 @@ UString UString::operator+(const UString &str) const {
return tmp;
}

UString UString::operator+(const QString &str) const {
UString tmp(*this);

tmp += str;

return tmp;
}

UString UString::operator+(const std::string &str) const {
UString tmp(*this);

Expand Down Expand Up @@ -164,12 +140,6 @@ UString &UString::operator+=(const UString &str) {
return *this;
}

UString &UString::operator+=(const QString &str) {
UString ustr(str);

return *this += ustr;
}

UString &UString::operator+=(const std::string &str) {
UString ustr(str);

Expand Down Expand Up @@ -278,10 +248,6 @@ const char *UString::c_str() const {
return _string.c_str();
}

QString UString::toQString() const {
return QString::fromStdString(_string);
}

UString::iterator UString::begin() const {
return iterator(_string.begin(), _string.begin(), _string.end());
}
Expand Down
13 changes: 0 additions & 13 deletions src/common/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@
#ifndef COMMON_USTRING_H
#define COMMON_USTRING_H

#include <QString>

#include <string>
#include <sstream>
#include <vector>

#include <boost/functional/hash.hpp>

#include <QString>

#include "src/common/types.h"
#include "src/common/system.h"

Expand Down Expand Up @@ -71,8 +67,6 @@ class UString {
UString();
/** Copy constructor. */
UString(const UString &str);
/** Construct UString from a QString. */
UString(const QString &str);
/** Construct UString from an UTF-8 string. */
UString(const std::string &str);
/** Construct UString from an UTF-8 string. */
Expand All @@ -85,10 +79,7 @@ class UString {
UString(iterator sBegin, iterator sEnd);
~UString();

operator QString() const;

UString &operator=(const UString &str);
UString &operator=(const QString &str);
UString &operator=(const std::string &str);
UString &operator=(const char *str);

Expand All @@ -98,13 +89,11 @@ class UString {
bool operator>(const UString &str) const;

UString operator+(const UString &str) const;
UString operator+(const QString &str) const;
UString operator+(const std::string &str) const;
UString operator+(const char *str) const;
UString operator+(uint32 c) const;

UString &operator+=(const UString &str);
UString &operator+=(const QString &str);
UString &operator+=(const std::string &str);
UString &operator+=(const char *str);
UString &operator+=(uint32 c);
Expand Down Expand Up @@ -133,8 +122,6 @@ class UString {
/** Return the (utf8 encoded) string data. */
const char *c_str() const;

QString toQString() const;

iterator begin() const;
iterator end() const;

Expand Down
24 changes: 12 additions & 12 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "src/common/filepath.h"
#include "src/common/strutil.h"
#include "src/common/system.h"
#include "src/common/ustring.h"
#include "src/common/writefile.h"
#include "src/gui/config.h"
#include "src/gui/mainwindow.h"
Expand All @@ -53,7 +54,7 @@ namespace GUI {

W_OBJECT_IMPL(MainWindow)

MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, const Common::UString &path)
MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, const char *path)
: QMainWindow(parent) {
_centralWidget = new QWidget(this);
_centralLayout = new QGridLayout(_centralWidget);
Expand Down Expand Up @@ -220,15 +221,12 @@ MainWindow::MainWindow(QWidget *parent, const char *title, const QSize &size, co
_status = std::make_shared<StatusBar>(this->statusBar());
_status->setText("Idle...");

// open the path given in command line if any
if (path.empty()) {
// nothing is open yet
const QString qpath = QString::fromUtf8(path);

if (qpath.isEmpty())
_actionClose->setEnabled(false);
}
else {
_rootPath = path.toQString();
setTreeViewModel(_rootPath);
}
else
setTreeViewModel(qpath);
}

MainWindow::~MainWindow() {
Expand Down Expand Up @@ -454,7 +452,8 @@ void MainWindow::exportBMUMP3() {

const QString title = "Save MP3 file";
const QString mask = "MP3 file (*.mp3)|*.mp3";
const QString def = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeMP3).toQString();
const char *defCstr = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeMP3).c_str();
const QString def = QString::fromUtf8(defCstr);

QString fileName = QFileDialog::getSaveFileName(this,
title, def,
Expand Down Expand Up @@ -565,7 +564,8 @@ void MainWindow::exportWAV() {

const QString title = "Save PCM WAV file";
const QString mask = "WAV file (*.wav)|*.wav";
const QString def = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeWAV).toQString();
const char *defCstr = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeWAV).c_str();
const QString def = QString::fromUtf8(defCstr);

QString fileName = QFileDialog::getSaveFileName(this,
title, def,
Expand Down Expand Up @@ -596,7 +596,7 @@ void MainWindow::exportWAV() {
}

void MainWindow::slotAbout() {
QString msg = createVersionText().toQString();
const QString msg = QString::fromUtf8(createVersionText().c_str());
QMessageBox::about(this, "About Phaethon", msg);
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "verdigris/wobjectdefs.h"

#include "src/common/readstream.h"
#include "src/common/ustring.h"
#include "src/common/writestream.h"
#include "src/gui/statusbar.h"
#include "src/sound/sound.h"
Expand All @@ -62,7 +61,7 @@ class MainWindow : public QMainWindow {
W_OBJECT(MainWindow)

public:
MainWindow(QWidget *parent, const char *title, const QSize &size, const Common::UString &path);
MainWindow(QWidget *parent, const char *title, const QSize &size, const char *path);
~MainWindow();

std::shared_ptr<StatusBar> status();
Expand Down
1 change: 0 additions & 1 deletion src/gui/panelpreviewsound.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include "verdigris/wobjectdefs.h"

#include "src/common/ustring.h"
#include "src/sound/types.h"

namespace GUI {
Expand Down
6 changes: 3 additions & 3 deletions src/gui/panelresourceinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const QString getSizeLabel(size_t size) {
if (size < 1024)
return QString("%1").arg(size);

QString humanRead = Common::FilePath::getHumanReadableSize(size).toQString();
QString humanRead = QString::fromUtf8(Common::FilePath::getHumanReadableSize(size).c_str());

return QString("%1 (%2)").arg(humanRead).arg(size);
}
Expand All @@ -141,7 +141,7 @@ const QString getFileTypeLabel(Aurora::FileType type) {
QString label = QString("%1").arg(type);

if (type != Aurora::kFileTypeNone) {
QString temp = TypeMan.getExtension(type).toQString();
QString temp = QString::fromUtf8(TypeMan.getExtension(type).c_str());
label += QString(" (%1)").arg(temp);
}

Expand All @@ -152,7 +152,7 @@ const QString getResTypeLabel(Aurora::ResourceType type) {
QString label = QString("%1").arg(type);

if (type != Aurora::kResourceNone) {
QString temp = getResourceTypeDescription(type).toQString();
QString temp = QString::fromUtf8(getResourceTypeDescription(type).c_str());
label += QString(" (%1)").arg(temp);
}

Expand Down
8 changes: 4 additions & 4 deletions src/gui/resourcetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Aurora::Archive *ResourceTree::getArchive(const QString &path) {
return a->second;

Aurora::Archive *arch = 0;
switch (TypeMan.getFileType(path)) {
switch (TypeMan.getFileType(path.toStdString().c_str())) {
case Aurora::kFileTypeZIP:
arch = new Aurora::ZIPFile(new Common::ReadFile(path.toStdString().c_str()));
break;
Expand Down Expand Up @@ -341,7 +341,7 @@ Aurora::KEYDataFile *ResourceTree::getKEYDataFile(const QString &file) {
if (path.empty())
throw Common::Exception("No such file or directory \"%s\"", (_root->getPath() + "/" + file).toStdString().c_str());

Aurora::FileType type = TypeMan.getFileType(file);
Aurora::FileType type = TypeMan.getFileType(file.toStdString().c_str());

Aurora::KEYDataFile *dataFile = 0;
switch (type) {
Expand All @@ -366,9 +366,9 @@ void ResourceTree::loadKEYDataFiles(Aurora::KEYFile &key) {
for (uint i = 0; i < dataFiles.size(); i++) {
try {

_mainWindow->status()->push(tr("Loading data file") + dataFiles[i].toQString() + "...");
_mainWindow->status()->push(tr("Loading data file") + QString::fromUtf8(dataFiles[i].c_str()) + "...");

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

_mainWindow->status()->pop();
Expand Down
10 changes: 5 additions & 5 deletions src/gui/resourcetreeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ ItemData::ItemData(const QString &parentPath, const QString &fileName, Aurora::A
_fullPath = parentPath + "/" + fileName;
_isDir = false;
_source = kSourceArchiveFile;
_fileType = TypeMan.getFileType(fileName);
_resourceType = TypeMan.getResourceType(fileName);
_fileType = TypeMan.getFileType(fileName.toStdString().c_str());
_resourceType = TypeMan.getResourceType(fileName.toStdString().c_str());
_size = archiveData->getResourceSize(resource.index);

_archive.data = archiveData;
Expand All @@ -56,8 +56,8 @@ ItemData::ItemData(const QString &fullPath, const QFileInfo &info) {
_resourceType = Aurora::kResourceNone;
}
else {
_fileType = TypeMan.getFileType(info.fileName());
_resourceType = TypeMan.getResourceType(info.fileName());
_fileType = TypeMan.getFileType(info.fileName().toStdString().c_str());
_resourceType = TypeMan.getResourceType(info.fileName().toStdString().c_str());
}

_archive.data = 0;
Expand All @@ -72,7 +72,7 @@ ItemData::ItemData(const QString &fullPath, const QFileInfo &info) {
ResourceTreeItem::ResourceTreeItem(Aurora::Archive *archiveData, Aurora::Archive::Resource &resource, ResourceTreeItem *parent)
: _parent(parent)
{
QString fileName = TypeMan.setFileType(resource.name, resource.type).toQString();
QString fileName = QString::fromUtf8(TypeMan.setFileType(resource.name, resource.type).c_str());
_name = fileName;

_data = new ItemData(parent->getPath(), fileName, archiveData, resource);
Expand Down
11 changes: 3 additions & 8 deletions src/phaethon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
* The project's main entry point.
*/

#include <cstdio>

#include <QApplication>

#include "src/version/version.h"

#include "src/common/util.h"
#include "src/common/error.h"
#include "src/common/ustring.h"
#include "src/common/platform.h"

#include "src/sound/sound.h"

#include "src/gui/mainwindow.h"
#include "src/sound/sound.h"
#include "src/version/version.h"

#include "src/cline.h"

Expand Down Expand Up @@ -64,7 +59,7 @@ Phaethon::Phaethon(const Common::UString &path) : _path(path) {
char *argv[] = {empty}; // must be at least 1
QApplication app(argc, argv);

GUI::MainWindow mainWindow(0, Version::getProjectNameVersion(), QSize(800, 600), path);
GUI::MainWindow mainWindow(0, Version::getProjectNameVersion(), QSize(800, 600), path.c_str());
mainWindow.show();

app.exec();
Expand Down

0 comments on commit 072ce9e

Please sign in to comment.