QTfrontend/ui/page/pagemain.cpp
changeset 9833 1957c7f92460
parent 9832 b1038b4373cc
child 9835 e89b42c55047
equal deleted inserted replaced
9832:b1038b4373cc 9833:1957c7f92460
   119     return bottomLayout;
   119     return bottomLayout;
   120 }
   120 }
   121 
   121 
   122 void PageMain::connectSignals()
   122 void PageMain::connectSignals()
   123 {
   123 {
       
   124 #ifndef QT_DEBUG
       
   125     connect(this, SIGNAL(pageEnter()), this, SLOT(updateTip()));
       
   126 #endif
   124     connect(BtnNet, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice()));
   127     connect(BtnNet, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice()));
   125     //connect(BtnNetLocal, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice()));
   128     //connect(BtnNetLocal, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice()));
   126     //connect(BtnNetOfficial, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice()));
   129     //connect(BtnNetOfficial, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice()));
   127     // TODO: add signal-forwarding required by (currently missing) encapsulation
   130     // TODO: add signal-forwarding required by (currently missing) encapsulation
   128 }
   131 }
   132     initPage();
   135     initPage();
   133 
   136 
   134     if(frontendEffects)
   137     if(frontendEffects)
   135         setAttribute(Qt::WA_NoSystemBackground, true);
   138         setAttribute(Qt::WA_NoSystemBackground, true);
   136     mainNote->setOpenExternalLinks(true);
   139     mainNote->setOpenExternalLinks(true);
   137 
       
   138 #ifdef QT_DEBUG
   140 #ifdef QT_DEBUG
   139     setDefaultDescription(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game, while some features might be broken or incomplete!"));
   141     setDefaultDescription(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game, while some features might be broken or incomplete!"));
   140 #else
   142 #else
   141     setDefaultDescription(QLabel::tr("Tip: %1").arg(randomTip()));
   143     setDefaultDescription(QLabel::tr("Tip: %1").arg(randomTip()));
   142 #endif
   144 #endif
   143 
   145 }
   144 }
   146 
   145 
   147 void PageMain::updateTip()
   146 QString PageMain::randomTip() const
   148 {
       
   149     setDefaultDescription(QLabel::tr("Tip: %1").arg(randomTip()));
       
   150 }
       
   151 
       
   152 QString PageMain::randomTip()
   147 {
   153 {
   148 #ifdef _WIN32
   154 #ifdef _WIN32
   149     int platform = 1;
   155     int platform = 1;
   150 #elif defined __APPLE__
   156 #elif defined __APPLE__
   151     int platform = 2;
   157     int platform = 2;
   152 #else
   158 #else
   153     int platform = 3;
   159     int platform = 3;
   154 #endif
   160 #endif
   155     DataManager & dataMgr = DataManager::instance();
   161     if(Tips.length() == 0)
   156 
   162     {
   157     // get locale
   163         DataManager & dataMgr = DataManager::instance();
   158     QSettings settings(dataMgr.settingsFileName(),
   164 
   159                        QSettings::IniFormat);
   165         // get locale
   160 
   166         QSettings settings(dataMgr.settingsFileName(),
   161     QString loc = settings.value("misc/locale", "").toString();
   167                            QSettings::IniFormat);
   162     if (loc.isEmpty())
   168 
   163         loc = QLocale::system().name();
   169         QString loc = settings.value("misc/locale", "").toString();
   164 
   170         if (loc.isEmpty())
   165     QString tipFile = QString("physfs://Locale/tips_" + loc + ".xml");
   171             loc = QLocale::system().name();
   166 
   172 
   167     // if file is non-existant try with language only
   173         QString tipFile = QString("physfs://Locale/tips_" + loc + ".xml");
   168     if (!QFile::exists(tipFile))
   174 
   169         tipFile = QString("physfs://Locale/tips_" + loc.remove(QRegExp("_.*$")) + ".xml");
   175         // if file is non-existant try with language only
   170 
   176         if (!QFile::exists(tipFile))
   171     // fallback if file for current locale is non-existant
   177             tipFile = QString("physfs://Locale/tips_" + loc.remove(QRegExp("_.*$")) + ".xml");
   172     if (!QFile::exists(tipFile))
   178 
   173         tipFile = QString("physfs://Locale/tips_en.xml");
   179         // fallback if file for current locale is non-existant
   174 
   180         if (!QFile::exists(tipFile))
   175     QStringList Tips;
   181             tipFile = QString("physfs://Locale/tips_en.xml");
   176     QFile file(tipFile);
   182 
   177     file.open(QIODevice::ReadOnly);
   183         QFile file(tipFile);
   178     QTextStream in(&file);
   184         file.open(QIODevice::ReadOnly);
   179     QString line = in.readLine();
   185         QTextStream in(&file);
   180     int tip_platform = 0;
   186         QString line = in.readLine();
   181     while (!line.isNull()) {
   187         int tip_platform = 0;
   182         if(line.contains("<windows-only>", Qt::CaseSensitive))
   188         while (!line.isNull()) {
   183             tip_platform = 1;
   189             if(line.contains("<windows-only>", Qt::CaseSensitive))
   184         if(line.contains("<mac-only>", Qt::CaseSensitive))
   190                 tip_platform = 1;
   185             tip_platform = 2;
   191             if(line.contains("<mac-only>", Qt::CaseSensitive))
   186         if(line.contains("<linux-only>", Qt::CaseSensitive))
   192                 tip_platform = 2;
   187             tip_platform = 3;
   193             if(line.contains("<linux-only>", Qt::CaseSensitive))
   188         if(line.contains("</windows-only>", Qt::CaseSensitive) ||
   194                 tip_platform = 3;
   189                 line.contains("</mac-only>", Qt::CaseSensitive) ||
   195             if(line.contains("</windows-only>", Qt::CaseSensitive) ||
   190                 line.contains("</linux-only>", Qt::CaseSensitive)) {
   196                     line.contains("</mac-only>", Qt::CaseSensitive) ||
   191             tip_platform = 0;
   197                     line.contains("</linux-only>", Qt::CaseSensitive)) {
       
   198                 tip_platform = 0;
       
   199             }
       
   200             QStringList split_string = line.split(QRegExp("</?tip>"));
       
   201             if((tip_platform == platform || tip_platform == 0) && split_string.size() != 1)
       
   202                 Tips << tr(split_string[1].toLatin1().data(), "Tips");
       
   203             line = in.readLine();
   192         }
   204         }
   193         QStringList split_string = line.split(QRegExp("</?tip>"));
   205         // The following tip will require links to app store entries first.
   194         if((tip_platform == platform || tip_platform == 0) && split_string.size() != 1)
   206         //Tips << tr("Want to play Hedgewars any time? Grab the Mobile version for %1 and %2.", "Tips").arg("").arg("");
   195             Tips << tr(split_string[1].toLatin1().data(), "Tips");
   207         // the ios version is located here: http://itunes.apple.com/us/app/hedgewars/id391234866
   196         line = in.readLine();
   208 
       
   209         file.close();
   197     }
   210     }
   198     // The following tip will require links to app store entries first.
       
   199     //Tips << tr("Want to play Hedgewars any time? Grab the Mobile version for %1 and %2.", "Tips").arg("").arg("");
       
   200     // the ios version is located here: http://itunes.apple.com/us/app/hedgewars/id391234866
       
   201 
       
   202     file.close();
       
   203     return Tips[QTime(0, 0, 0).secsTo(QTime::currentTime()) % Tips.length()];
   211     return Tips[QTime(0, 0, 0).secsTo(QTime::currentTime()) % Tips.length()];
   204 }
   212 }
   205 
   213 
   206 void PageMain::toggleNetworkChoice()
   214 void PageMain::toggleNetworkChoice()
   207 {
   215 {