14 * You should have received a copy of the GNU General Public License |
14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software |
15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 */ |
17 */ |
18 |
18 |
19 #include <QApplication> |
19 #include "HWApplication.h" |
|
20 |
20 #include <QTranslator> |
21 #include <QTranslator> |
21 #include <QLocale> |
22 #include <QLocale> |
22 #include <QMessageBox> |
23 #include <QMessageBox> |
23 #include <QPlastiqueStyle> |
24 #include <QPlastiqueStyle> |
24 #include <QRegExp> |
25 #include <QRegExp> |
25 #include <QMap> |
26 #include <QMap> |
26 #include <QSettings> |
27 #include <QSettings> |
|
28 #include <QStringListModel> |
27 |
29 |
28 #include "hwform.h" |
30 #include "hwform.h" |
29 #include "hwconsts.h" |
31 #include "hwconsts.h" |
30 |
32 |
31 #ifdef _WIN32 |
33 #ifdef _WIN32 |
49 } |
51 } |
50 return true; |
52 return true; |
51 } |
53 } |
52 |
54 |
53 int main(int argc, char *argv[]) { |
55 int main(int argc, char *argv[]) { |
54 QApplication app(argc, argv); |
56 HWApplication app(argc, argv); |
55 app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
57 app.setAttribute(Qt::AA_DontShowIconsInMenus,false); |
56 |
58 |
57 QStringList arguments = app.arguments(); |
59 QStringList arguments = app.arguments(); |
58 QMap<QString, QString> parsedArgs; |
60 QMap<QString, QString> parsedArgs; |
59 { |
61 { |
381 "Please check your installation"). |
383 "Please check your installation"). |
382 arg(datadir->absolutePath()+"/hedgewars/Data")); |
384 arg(datadir->absolutePath()+"/hedgewars/Data")); |
383 return 1; |
385 return 1; |
384 } |
386 } |
385 |
387 |
386 Themes = new QStringList(); |
388 { |
387 QFile userthemesfile(cfgdir->absolutePath() + "/Data/Themes/themes.cfg"); |
389 QDir dir; |
388 if (userthemesfile.open(QIODevice::ReadOnly)) { |
390 dir.setPath(cfgdir->absolutePath() + "/Data/Themes"); |
389 QTextStream stream(&userthemesfile); |
391 |
390 while (!stream.atEnd()) Themes->append(stream.readLine()); |
392 QStringList themes; |
391 userthemesfile.close(); |
393 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
392 } |
394 |
393 QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
395 dir.setPath(datadir->absolutePath() + "/Themes"); |
394 QString str; |
396 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
395 if (themesfile.open(QIODevice::ReadOnly)) { |
397 |
396 QTextStream stream(&themesfile); |
398 QList<QPair<QIcon, QIcon> > icons; |
397 while (!stream.atEnd()) { |
399 |
398 str = stream.readLine(); |
400 for(int i = themes.size() - 1; i >= 0; --i) |
399 if (!Themes->contains(str)) Themes->append(str); |
401 { |
400 } |
402 QFile tmpfile; |
401 themesfile.close(); |
403 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
402 } else { |
404 if (!tmpfile.exists()) |
403 QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK"); |
405 { |
|
406 tmpfile.setFileName(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
|
407 if(tmpfile.exists()) |
|
408 { // load icon |
|
409 QPair<QIcon, QIcon> ic; |
|
410 ic.first = QIcon(QFileInfo(tmpfile).absoluteFilePath()); |
|
411 |
|
412 QFile previewIconFile; |
|
413 previewIconFile.setFileName(QString("%1/Data/Themes/%2/icon@2x.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
|
414 if (previewIconFile.exists()) ic.second = QIcon(QFileInfo(previewIconFile).absoluteFilePath()); |
|
415 else ic.second = QIcon(QString("%1/Themes/%2/icon@2x.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
|
416 |
|
417 icons.prepend(ic); |
|
418 } |
|
419 else |
|
420 { |
|
421 themes.removeAt(i); |
|
422 } |
|
423 } |
|
424 } |
|
425 |
|
426 themesModel = new ThemesModel(themes); |
|
427 for(int i = 0; i < icons.size(); ++i) |
|
428 { |
|
429 themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole); |
|
430 themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole); |
|
431 |
|
432 qDebug() << "icon test" << themesModel->index(i).data(Qt::UserRole).toString(); |
|
433 } |
404 } |
434 } |
405 |
435 |
406 QDir tmpdir; |
436 QDir tmpdir; |
407 tmpdir.cd(cfgdir->absolutePath()); |
437 tmpdir.cd(cfgdir->absolutePath()); |
408 tmpdir.cd("Data/Maps"); |
438 tmpdir.cd("Data/Maps"); |
429 if (!scriptList->contains(*it,Qt::CaseInsensitive)) scriptList->append(*it); |
459 if (!scriptList->contains(*it,Qt::CaseInsensitive)) scriptList->append(*it); |
430 |
460 |
431 QTranslator Translator; |
461 QTranslator Translator; |
432 { |
462 { |
433 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
463 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
434 QString cc = settings.value("misc/locale", "").toString(); |
464 QString cc = settings.value("misc/locale", QString()).toString(); |
435 if(!cc.compare("")) |
465 if(cc.isEmpty()) |
436 cc = QLocale::system().name(); |
466 cc = QLocale::system().name(); |
437 QFile tmpfile; |
467 QFile tmpfile; |
438 tmpfile.setFileName(cfgdir->absolutePath() + "Data/Locale/hedgewars_" + cc); |
468 tmpfile.setFileName(cfgdir->absolutePath() + "Data/Locale/hedgewars_" + cc); |
439 if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "Locale/hedgewars_" + cc); |
469 if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "Locale/hedgewars_" + cc); |
440 Translator.load(QFileInfo(tmpfile).absoluteFilePath()); |
470 Translator.load(QFileInfo(tmpfile).absoluteFilePath()); |