src/misc.cpp

changeset 37
c82a86ea87be
parent 30
6b82f6a3ad53
child 39
2c368cf5cc19
equal deleted inserted replaced
36:b8fa9171be6e 37:c82a86ea87be
1 /* 1 /*
2 * ZCinema: Zandronum demo launcher 2 * ZCinema: Zandronum demo launcher
3 * Copyright (C) 2013 Santeri Piippo 3 * Copyright (C) 2013-2015 Teemu Piippo
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or 7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
17 */ 17 */
18 18
19 #include "misc.h" 19 #include "misc.h"
20 #include <QMessageBox> 20 #include <QMessageBox>
21 21
22 EXTERN_CONFIG (List, devBuildNames) 22 uint32 makeByteID (uint8 a, uint8 b, uint8 c, uint8 d)
23 EXTERN_CONFIG (List, releaseNames) 23 {
24 EXTERN_CONFIG (Map, binaryPaths)
25
26 uint32 makeByteID (uint8 a, uint8 b, uint8 c, uint8 d) {
27 return a | (b << 8) | (c << 16) | (d << 24); 24 return a | (b << 8) | (c << 16) | (d << 24);
28 } 25 }
29 26
30 // ============================================================================= 27 //
31 // ----------------------------------------------------------------------------- 28 // -----------------------------------------------------------------------------
32 QList<QVariant> getVersions() { 29 //
33 return cfg::devBuildNames + cfg::releaseNames; 30
31 QList<QVariant> getVersions()
32 {
33 return Config::get ("versions").toList();
34 } 34 }
35 35
36 // ============================================================================= 36 //
37 // ----------------------------------------------------------------------------- 37 // -----------------------------------------------------------------------------
38 str binaryConfigName (str ver) { 38 //
39 return fmt ("binaries/%1", ver); 39
40 void addVersion (const ZandronumVersion& version)
41 {
42 QList<QVariant> versions = getVersions();
43 QVariant var;
44 var.setValue (version);
45 versions.append (var);
46 Config::set ("versions", versions);
40 } 47 }
41 48
42 // ============================================================================= 49 //
43 // ----------------------------------------------------------------------------- 50 // -----------------------------------------------------------------------------
44 void addVersion (str name, bool isRelease, str binaryPath) { 51 //
45 cfg::binaryPaths[name] = binaryPath;
46
47 if (isRelease)
48 cfg::releaseNames << QVariant (name);
49 else
50 cfg::devBuildNames << QVariant (name);
51
52 cfg::save();
53 }
54 52
55 // ============================================================================= 53 QString basename (const QString& path)
56 // ----------------------------------------------------------------------------- 54 {
57 str basename (str path) { 55 int lastpos = path.lastIndexOf ("/");
58 long lastpos = path.lastIndexOf ("/"); 56
59
60 if (lastpos != -1) 57 if (lastpos != -1)
61 return path.mid (lastpos + 1); 58 return path.mid (lastpos + 1);
62 59
63 return path; 60 return path;
64 } 61 }
65 62
66 // ============================================================================= 63 //
67 // ----------------------------------------------------------------------------- 64 // -----------------------------------------------------------------------------
68 bool confirm (str text) { 65 //
69 return QMessageBox::question (null, QObject::tr ("Confirm"), text, 66
67 bool confirm (const QString& text)
68 {
69 return QMessageBox::question (NULL, QObject::tr ("Confirm"), text,
70 QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::No; 70 QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::No;
71 } 71 }

mercurial