Implement some bits and pieces, disable dead buttons.

This commit is contained in:
Petr Mrázek 2013-06-23 22:10:32 +02:00
parent d9195bff3a
commit 27b1de0d6d
10 changed files with 127 additions and 119 deletions

View File

@ -64,7 +64,8 @@
// Opens the given file in the default application.
// TODO: Move this somewhere.
void openInDefaultProgram ( QString filename );
void openFileInDefaultProgram ( QString filename );
void openDirInDefaultProgram ( QString dirpath, bool ensureExists = false );
MainWindow::MainWindow ( QWidget *parent ) :
QMainWindow ( parent ),
@ -224,16 +225,22 @@ void MainWindow::on_actionChangeInstGroup_triggered()
Instance* inst = selectedInstance();
if(inst)
{
bool ok = false;
QString name ( inst->group() );
name = QInputDialog::getText ( this, tr ( "Group name" ), tr ( "Enter a new group name." ), QLineEdit::Normal, name );
inst->setGroup(name);
QInputDialog dlg(this);
dlg.result();
name = QInputDialog::getText ( this, tr ( "Group name" ), tr ( "Enter a new group name." ),
QLineEdit::Normal, name, &ok );
if(ok)
inst->setGroup(name);
}
}
void MainWindow::on_actionViewInstanceFolder_triggered()
{
openInDefaultProgram ( globalSettings->get ( "InstanceDir" ).toString() );
QString str = globalSettings->get ( "InstanceDir" ).toString();
openDirInDefaultProgram ( str );
}
void MainWindow::on_actionRefresh_triggered()
@ -243,7 +250,7 @@ void MainWindow::on_actionRefresh_triggered()
void MainWindow::on_actionViewCentralModsFolder_triggered()
{
openInDefaultProgram ( globalSettings->get ( "CentralModsDir" ).toString() );
openDirInDefaultProgram ( globalSettings->get ( "CentralModsDir" ).toString() , true);
}
void MainWindow::on_actionCheckUpdate_triggered()
@ -282,6 +289,37 @@ void MainWindow::on_mainToolBar_visibilityChanged ( bool )
ui->mainToolBar->setVisible ( true );
}
void MainWindow::on_actionDeleteInstance_triggered()
{
}
void MainWindow::on_actionRenameInstance_triggered()
{
Instance* inst = selectedInstance();
if(inst)
{
bool ok = false;
QString name ( inst->name() );
name = QInputDialog::getText ( this, tr ( "Instance name" ), tr ( "Enter a new instance name." ),
QLineEdit::Normal, name, &ok );
//FIXME: dialog should do the validation!!!
if(ok && name.length() && name.length() <= 25)
inst->setName(name);
}
}
void MainWindow::on_actionViewSelectedInstFolder_triggered()
{
Instance* inst = selectedInstance();
if(inst)
{
QString str = inst->rootDir();
openDirInDefaultProgram ( QDir(str).absolutePath() );
}
}
void MainWindow::closeEvent ( QCloseEvent *event )
{
// Save the window state and geometry.
@ -449,7 +487,18 @@ void MainWindow::openWebPage ( QUrl url )
browser->exec();
}
void openInDefaultProgram ( QString filename )
void openDirInDefaultProgram ( QString path, bool ensureExists )
{
QDir parentPath;
QDir dir( path );
if(!dir.exists())
{
parentPath.mkpath(dir.absolutePath());
}
QDesktopServices::openUrl ( "file:///" + dir.absolutePath() );
}
void openFileInDefaultProgram ( QString filename )
{
QDesktopServices::openUrl ( "file:///" + QFileInfo ( filename ).absolutePath() );
}

View File

@ -63,6 +63,8 @@ private slots:
void on_actionChangeInstGroup_triggered();
void on_actionViewInstanceFolder_triggered();
void on_actionViewSelectedInstFolder_triggered();
void on_actionRefresh_triggered();
@ -82,8 +84,11 @@ private slots:
void on_actionLaunchInstance_triggered();
void on_actionMakeDesktopShortcut_triggered();
void on_actionDeleteInstance_triggered();
void on_actionRenameInstance_triggered();
void on_actionMakeDesktopShortcut_triggered();
void on_actionChangeInstMCVersion_triggered();

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
<width>692</width>
<height>596</height>
</rect>
</property>
<property name="windowTitle">
@ -271,6 +271,9 @@
</property>
</action>
<action name="actionChangeInstIcon">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Change Icon</string>
</property>
@ -282,6 +285,9 @@
</property>
</action>
<action name="actionEditInstNotes">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit Notes</string>
</property>
@ -293,6 +299,9 @@
</property>
</action>
<action name="actionInstanceSettings">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Settings</string>
</property>
@ -304,6 +313,9 @@
</property>
</action>
<action name="actionMakeDesktopShortcut">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Make Shortcut</string>
</property>
@ -315,6 +327,9 @@
</property>
</action>
<action name="actionManageInstSaves">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Manage Saves</string>
</property>
@ -326,6 +341,9 @@
</property>
</action>
<action name="actionEditInstMods">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit Mods</string>
</property>
@ -359,6 +377,9 @@
</property>
</action>
<action name="actionRebuildInstJar">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Rebuild Jar</string>
</property>

View File

@ -45,8 +45,6 @@ public slots:
void changeStatus(const QString& status);
void changeProgress(int progress);
void test() { qDebug("Lol"); }
signals:

View File

@ -49,18 +49,6 @@ class LIBMULTIMC_EXPORT InstVersion : public QObject
*/
Q_PROPERTY(QString typeName READ typeName)
/*!
* Whether or not this is a meta version.
* Meta versions are not real versions, merely versions that act as aliases
* for other versions.
* For example: There could be a meta version called "Latest" that always
* points to the latest version. The user would pick this version and when
* a new version came out, it would point to the new one and update the instance
* automatically.
*/
Q_PROPERTY(bool isMeta READ isMeta)
/*!
* Gets the version's timestamp.
* This is primarily used for sorting versions in a list.
@ -93,7 +81,6 @@ public:
virtual QString name() const;
virtual QString typeName() const = 0;
virtual qint64 timestamp() const;
virtual bool isMeta() const;
virtual InstVersionList *versionList() const;

View File

@ -29,6 +29,11 @@ class LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion
*/
Q_PROPERTY(VersionType versionType READ versionType WRITE setVersionType)
/*!
* This version's launcher. Used to identify the launcher version this is intended for.
*/
Q_PROPERTY(LauncherVersion versionType READ launcherVersion WRITE setLauncherVersion)
/*!
* The URL that this version will be downloaded from.
*/
@ -39,10 +44,6 @@ class LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion
*/
Q_PROPERTY(QString etag READ etag)
/*!
* True if this is a version from the new Minecraft launcher's version list.
*/
Q_PROPERTY(bool isForNewLauncher READ isForNewLauncher WRITE setIsForNewLauncher)
public:
explicit MinecraftVersion(QString descriptor,
@ -52,15 +53,6 @@ public:
QString etag,
InstVersionList *parent = 0);
/*!
* Creates a meta version that links to the given version.
* This is *NOT* a copy constructor.
* \param linkedVersion the version that the meta version will link to.
*/
explicit MinecraftVersion(const MinecraftVersion *linkedVersion);
MinecraftVersion(const MinecraftVersion &other, QObject *parent);
static InstVersion *mcnVersion(QString rawName, QString niceName);
enum VersionType
@ -69,10 +61,14 @@ public:
Stable,
CurrentStable,
Snapshot,
MCNostalgia,
MetaCustom,
MetaLatestSnapshot,
MetaLatestStable
MCNostalgia
};
enum LauncherVersion
{
Unknown = -1,
Legacy = 0, // the legacy launcher that's been around since ... forever
Launcher16 = 1, // current launcher as of 26/06/2013
};
virtual QString descriptor() const;
@ -80,24 +76,22 @@ public:
virtual QString typeName() const;
virtual qint64 timestamp() const;
virtual bool isForNewLauncher() const;
virtual void setIsForNewLauncher(bool val);
virtual VersionType versionType() const;
virtual void setVersionType(VersionType typeName);
virtual LauncherVersion launcherVersion() const;
virtual void setLauncherVersion(LauncherVersion launcherVersion);
virtual QString downloadURL() const;
virtual QString etag() const;
virtual bool isMeta() const;
virtual InstVersion *copyVersion(InstVersionList *newParent) const;
private:
InstVersion *m_linkedVersion;
QString m_dlUrl;
QString m_etag;
VersionType m_type;
LauncherVersion m_launcherVersion;
bool m_isNewLauncherVersion;
};

View File

@ -73,7 +73,8 @@ void GameUpdateTask::executeTask()
// we're downloading from.
QString jarFilename = "minecraft";
if (targetVersion->isForNewLauncher())
// FIXME: this is NOT enough
if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16)
jarFilename = targetVersion->descriptor();
QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar";

View File

@ -51,12 +51,6 @@ bool InstVersion::isGreaterThan(const InstVersion &other) const
return timestamp() > other.timestamp();
}
bool InstVersion::isMeta() const
{
return false;
}
QString InstVersion::descriptor() const
{
return m_descriptor;

View File

@ -23,29 +23,9 @@ MinecraftVersion::MinecraftVersion(QString descriptor,
InstVersionList *parent) :
InstVersion(descriptor, name, timestamp, parent), m_dlUrl(dlUrl), m_etag(etag)
{
m_linkedVersion = NULL;
m_isNewLauncherVersion = false;
}
MinecraftVersion::MinecraftVersion(const MinecraftVersion *linkedVersion) :
InstVersion(linkedVersion->descriptor(), linkedVersion->name(), linkedVersion->timestamp(),
linkedVersion->versionList())
{
m_linkedVersion = (MinecraftVersion *)linkedVersion;
}
MinecraftVersion::MinecraftVersion(const MinecraftVersion &other, QObject *parent) :
InstVersion(other, parent)
{
if (other.m_linkedVersion)
m_linkedVersion = other.m_linkedVersion;
else
{
m_dlUrl = other.downloadURL();
m_etag = other.etag();
}
}
QString MinecraftVersion::descriptor() const
{
return m_descriptor;
@ -58,9 +38,6 @@ QString MinecraftVersion::name() const
QString MinecraftVersion::typeName() const
{
if (m_linkedVersion)
return m_linkedVersion->typeName();
switch (versionType())
{
case OldSnapshot:
@ -78,17 +55,6 @@ QString MinecraftVersion::typeName() const
case MCNostalgia:
return "MCNostalgia";
case MetaCustom:
// Not really sure what this does, but it was in the code for v4,
// so it must be important... Right?
return "Custom Meta Version";
case MetaLatestSnapshot:
return "Latest Snapshot";
case MetaLatestStable:
return "Latest Stable";
default:
return QString("Unknown Type %1").arg(versionType());
}
@ -99,16 +65,6 @@ qint64 MinecraftVersion::timestamp() const
return m_timestamp;
}
bool MinecraftVersion::isForNewLauncher() const
{
return m_isNewLauncherVersion;
}
void MinecraftVersion::setIsForNewLauncher(bool val)
{
m_isNewLauncherVersion = val;
}
MinecraftVersion::VersionType MinecraftVersion::versionType() const
{
return m_type;
@ -129,26 +85,21 @@ QString MinecraftVersion::etag() const
return m_etag;
}
bool MinecraftVersion::isMeta() const
MinecraftVersion::LauncherVersion MinecraftVersion::launcherVersion() const
{
return versionType() == MetaCustom ||
versionType() == MetaLatestSnapshot ||
versionType() == MetaLatestStable;
return m_launcherVersion;
};
void MinecraftVersion::setLauncherVersion(LauncherVersion launcherVersion)
{
m_launcherVersion = launcherVersion;
}
InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
{
if (isMeta())
{
MinecraftVersion *version = new MinecraftVersion((MinecraftVersion *)m_linkedVersion);
return version;
}
else
{
MinecraftVersion *version = new MinecraftVersion(
descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
version->setVersionType(versionType());
version->setIsForNewLauncher(isForNewLauncher());
return version;
}
MinecraftVersion *version = new MinecraftVersion(
descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
version->setVersionType(versionType());
version->setLauncherVersion(launcherVersion());
return version;
}

View File

@ -200,6 +200,7 @@ void MCVListLoadTask::setSubStatus(const QString msg)
setStatus("Loading instance version list: " + msg);
}
// FIXME: we should have a local cache of the version list and a local cache of version data
bool MCVListLoadTask::loadFromVList()
{
QNetworkReply *vlistReply = netMgr->get(QNetworkRequest(QUrl(QString(MCVLIST_URLBASE) +
@ -276,10 +277,15 @@ bool MCVListLoadTask::loadFromVList()
else
versionType = MinecraftVersion::Stable;
}
else
else if(versionTypeStr == "snapshot")
{
versionType = MinecraftVersion::Snapshot;
}
else
{
// we don't know what to do with this...
continue;
}
// Get the download URL.
QString dlUrl = QString(MCVLIST_URLBASE) + versionID + "/";
@ -289,7 +295,7 @@ bool MCVListLoadTask::loadFromVList()
MinecraftVersion *mcVersion = new MinecraftVersion(
versionID, versionID, versionTime.toMSecsSinceEpoch(),
dlUrl, "");
mcVersion->setIsForNewLauncher(true);
mcVersion->setLauncherVersion(MinecraftVersion::Launcher16);
mcVersion->setVersionType(versionType);
tempList.append(mcVersion);
}
@ -340,7 +346,7 @@ bool MCVListLoadTask::loadFromAssets()
QDomNodeList contents = doc.elementsByTagName("Contents");
QRegExp mcRegex("/minecraft.jar$");
QRegExp snapshotRegex("[0-9][0-9]w[0-9][0-9][a-z]|pre|rc");
QRegExp snapshotRegex("[0-9][0-9]w[0-9][0-9][a-z]?|pre|rc");
for (int i = 0; i < contents.length(); i++)
{
@ -443,6 +449,8 @@ bool MCVListLoadTask::loadMCNostalgia()
{
QNetworkReply *mcnReply = netMgr->get(QNetworkRequest(QUrl(QString(MCN_URLBASE) + "?pversion=1&list=True")));
NetUtils::waitForNetRequest(mcnReply);
processedMCNReply = true;
updateStuff();
return true;
}