Ticket #1810: game2.patch
File game2.patch, 16.4 KB (added by , 18 years ago) |
---|
-
mythgame/mythgame/gametree.h
102 102 public slots: 103 103 void handleTreeListSelection(int, IntVector*); 104 104 void handleTreeListEntry(int, IntVector*); 105 void showImageTimeout(void); 105 106 106 107 protected: 107 108 void keyPressEvent(QKeyEvent *e); … … 125 126 UITextType *m_gameGenre; 126 127 UITextType *m_gameFavourite; 127 128 UIImageType *m_gameImage; 129 130 QTimer *timer; 128 131 }; 129 132 130 133 #endif -
mythgame/mythgame/game_settings.xml
21 21 <text>Game Players</text> 22 22 <text lang="IT">Impostazioni generali</text> 23 23 <text lang="ES">Opciones Reproductores</text> 24 <text lang="CA"> Opcions Generals</text>25 <text lang="DE"> Grundeinstellungen</text>24 <text lang="CA"></text> 25 <text lang="DE">Spielestarter</text> 26 26 <text lang="DK">Spil Systemer</text> 27 27 <text lang="NL">Algemeen</text> 28 28 <text lang="PT">Jogadores</text> … … 50 50 <text>Clear Game Data</text> 51 51 <text lang="IT">Impostazioni generali</text> 52 52 <text lang="ES">Borrar Datos</text> 53 <text lang="CA"> Opcions Generals</text>54 <text lang="DE"> Grundeinstellungen</text>53 <text lang="CA"></text> 54 <text lang="DE">Loesche Spieleliste</text> 55 55 <text lang="DK">Slet spil data</text> 56 <text lang="NL"> Algemeen</text>56 <text lang="NL"></text> 57 57 <text lang="PT">Apagar Dados de Jogos</text> 58 58 <text lang="SV">Generella instÀllningar</text> 59 59 <text lang="SI">SploÅ¡ne nastavitve</text> … … 61 61 <action>CLEAR_GAME_DATA</action> 62 62 </button> 63 63 64 <button> 65 <type>GAME_SETTINGS_GENERAL</type> 66 <text>Generate Screenshots</text> 67 <text lang="IT"></text> 68 <text lang="ES"></text> 69 <text lang="CA"></text> 70 <text lang="DE">Screenshots erzeugen</text> 71 <text lang="DK"></text> 72 <text lang="NL"></text> 73 <text lang="PT"></text> 74 <text lang="SV"></text> 75 <text lang="SI"></text> 76 <text lang="FI"></text> 77 <action>GENERATE_SCREENSHOTS</action> 78 </button> 64 79 65 80 </mythmenu> -
mythgame/mythgame/gamehandler.cpp
3 3 #include "rom_metadata.h" 4 4 5 5 #include <qobject.h> 6 #include <qapplication.h> 7 #include <qtimer.h> 8 #include <qprocess.h> 6 9 #include <qptrlist.h> 7 10 #include <qstringlist.h> 8 11 #include <iostream> … … 14 17 #include <mythtv/mythdialogs.h> 15 18 #include <mythtv/util.h> 16 19 20 QProcess *process; 21 QString screencmd; 22 17 23 using namespace std; 18 24 19 25 static QPtrList<GameHandler> *handlers = 0; … … 64 70 void GameHandler::updateSettings(GameHandler *handler) 65 71 { 66 72 MSqlQuery query(MSqlQuery::InitCon()); 67 query.exec("SELECT rompath, workingpath, commandline, screenshots, gameplayerid, gametype, extensions, spandisks 73 query.exec("SELECT rompath, workingpath, commandline, screenshots, gameplayerid, gametype, extensions, spandisks, screenshotenabled, screenshotcmd FROM gameplayers WHERE playername = \"" + handler->SystemName() + "\";"); 68 74 69 75 query.next(); 70 76 handler->rompath = query.value(0).toString(); … … 75 81 handler->gametype = query.value(5).toString(); 76 82 handler->validextensions = QStringList::split(",", query.value(6).toString().stripWhiteSpace().remove(" ")); 77 83 handler->spandisks = query.value(7).toInt(); 84 handler->screenshotenabled = query.value(8).toInt(); 85 handler->screenshotcmd = query.value(9).toInt(); 78 86 79 87 } 80 88 … … 131 139 cerr << "No romDB data read from database. Not imported?" << endl; 132 140 else 133 141 cerr << "Loaded " << romDB.count() << " items from romDB Database" << endl; 134 135 142 } 136 143 137 144 void GameHandler::GetMetadata(GameHandler *handler, QString rom, QString* Genre, QString* Year, … … 723 730 else if (!(handler = GetHandler(romdata))) 724 731 { 725 732 // Couldn't get handler so abort. 726 return ;733 return ; 727 734 } 728 735 QString exec = handler->SystemCmdLine(); 729 736 … … 806 813 handlers->append(handler); 807 814 } 808 815 816 void GameHandler::generateScreenshots(void) 817 { 818 checkHandlers(); 819 820 GameHandler *handler = handlers->first(); 821 822 MSqlQuery query(MSqlQuery::InitCon()); 823 while(handler) 824 { 825 updateSettings(handler); 826 if (handler->ScreenShotEnabled()) 827 { 828 829 QString thequery; 830 thequery = QString("SELECT romname, rompath, gamename, diskcount " 831 "FROM gamemetadata WHERE system = '%1';") 832 .arg(handler->SystemName()); 833 834 query.exec(thequery); 835 836 if (query.isActive() && query.size() >0) 837 { 838 while (query.next()) 839 { 840 QString romname = query.value(0).toString(); 841 QString rompath = query.value(1).toString(); 842 int diskcount = query.value(3).toInt(); 843 //Get the Extension via the RomInfo Class 844 RomInfo temp; 845 temp.setRomname(romname); 846 QString extension = temp.getExtension(); 847 848 QString basename = romname.left(romname.length() - (extension.length() + 2)); 849 850 QString exec = handler->SystemCmdLine(); 851 852 if (handler->GameType() != "PC") 853 { 854 QString arg = "\"" + rompath + 855 "/" + romname + "\""; 856 857 // If they specified a %s in the commandline place the romname 858 // in that location, otherwise tack it on to the end of 859 // the command. 860 if (exec.contains("%s") || handler->SpanDisks()) 861 { 862 exec = exec.replace(QRegExp("%s"),arg); 863 864 if (handler->SpanDisks()) 865 { 866 QRegExp rxp = QRegExp( "%d[0-4]", TRUE, FALSE ); 867 868 if (exec.contains(rxp)) 869 { 870 if (diskcount > 1) 871 { 872 // Chop off the extension, . and last character of the name which we are assuming is the disk # 873 QString rom; 874 QString diskid[] = { "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6" }; 875 876 for (int disk = 1; disk <= diskcount; disk++) 877 { 878 rom = QString("\"%1/%2%3.%4\"") 879 .arg(rompath) 880 .arg(basename) 881 .arg(disk) 882 .arg(extension); 883 exec = exec.replace(QRegExp(diskid[disk]),rom); 884 } 885 } 886 887 else 888 { // If there is only one disk make sure we replace %d1 just like %s 889 exec = exec.replace(QRegExp("%d1"),arg); 890 } 891 } 892 } 893 } 894 else 895 { 896 exec = exec + " \"" + 897 rompath + "/" + 898 romname + "\""; 899 } 900 } 901 902 QString savedir = QDir::currentDirPath (); 903 QDir d; 904 if (handler->SystemWorkingPath()) { 905 if (!d.cd(handler->SystemWorkingPath())) 906 { 907 cout << "Failed to change to specified Working Directory : " << handler->SystemWorkingPath() << endl; 908 } 909 } 910 911 if (handler->ScreenShotCmd().length() < 2) 912 screencmd = gContext->GetSetting("GameScreenshotCmd"); 913 else 914 screencmd = handler->ScreenShotCmd(); 915 916 if (screencmd.contains("%p")) 917 { 918 QString reptxt = handler->SystemScreenShots() + "/" + basename; 919 screencmd = screencmd.replace(QRegExp("%p"),reptxt); 920 } 921 922 if (screencmd.contains("%s")) 923 { 924 QString reptxt = rompath + "/" + romname; 925 screencmd = screencmd.replace(QRegExp("%s"),reptxt); 926 } 927 928 process = new QProcess(); 929 930 QStringList lst( QStringList::split( " ", exec ) ); 931 932 //Combine Parameters within "" to 1 Argument! 933 QStringList s2; 934 935 for(int i = 0; i < lst.count(); i++) 936 { 937 if(lst[i][0] == '"') 938 { 939 if(lst[i][lst[i].length()-1] == '"') 940 { 941 s2.append(lst[i]); 942 } 943 else 944 { 945 QString s = lst[i]; 946 s += " "; 947 948 for(int j = i+1; j < lst.count(); j++) 949 { 950 s += lst[j]; 951 if (s[s.length()-1] == '"') 952 { 953 s2.append(s); 954 i=j; 955 break; 956 } 957 else 958 s += " "; 959 } 960 } 961 } 962 else 963 s2.append(lst[i]); 964 } 965 process->setArguments(s2); 966 967 QString ShotTime = gContext->GetSetting("GameScreenshotTime"); 968 int myShotTime = ShotTime.toInt() * 1000; 969 970 QTimer::singleShot( myShotTime, this, SLOT( screenshotTimeout() ) ); 971 if (!process->start()) 972 cout << "Error running Process:" << exec << endl; 973 974 while (process->isRunning()){ qApp->processEvents(); } 975 976 977 } 978 } 979 } 980 handler = handlers->next(); 981 982 } 983 } 984 void GameHandler::screenshotTimeout(void) 985 { 986 myth_system(screencmd); 987 process->kill(); 988 } -
mythgame/mythgame/gamehandler.h
53 53 54 54 typedef QMap <QString, GameScan> GameScanMap; 55 55 56 class GameHandler 57 { 56 class GameHandler : public QObject 57 { 58 59 Q_OBJECT 60 58 61 public: 59 62 GameHandler() 60 63 { … … 78 81 void VerifyGameDB(GameHandler *handler); 79 82 80 83 static void clearAllGameData(void); 84 void generateScreenshots(void); 81 85 82 86 static int buildFileCount(QString directory, GameHandler *handler); 83 87 void buildFileList(QString directory, GameHandler *handler, … … 96 100 97 101 static RomInfo* create_rominfo(RomInfo* parent); 98 102 int SpanDisks() const { return spandisks; } 103 int ScreenShotEnabled() const { return screenshotenabled; } 99 104 QString SystemName() const { return systemname; } 100 105 QString SystemCmdLine() const { return commandline; } 101 106 QString SystemRomPath() const { return rompath; } … … 103 108 QString SystemScreenShots() const { return screenshots; } 104 109 uint GamePlayerID() const { return gameplayerid; } 105 110 QString GameType() const { return gametype; } 111 QString ScreenShotCmd() const { return screenshotcmd; } 112 113 public slots: 114 void screenshotTimeout(void); 106 115 107 116 protected: 108 117 static GameHandler* GetHandler(RomInfo *rominfo); … … 110 119 111 120 bool rebuild; 112 121 int spandisks; 122 int screenshotenabled; 113 123 QString systemname; 114 124 QString rompath; 115 125 QString commandline; … … 117 127 QString screenshots; 118 128 uint gameplayerid; 119 129 QString gametype; 130 QString screenshotcmd; 120 131 QStringList validextensions; 121 132 122 133 RomDBMap romDB; -
mythgame/mythgame/dbcheck.cpp
10 10 11 11 #include "gamesettings.h" 12 12 13 const QString currentDatabaseVersion = "101 2";13 const QString currentDatabaseVersion = "1013"; 14 14 15 15 static bool UpdateDBVersionNumber(const QString &newnumber) 16 16 { … … 320 320 } 321 321 322 322 323 if (dbver == "1012") 324 { 325 const QString updates[] = { 326 "ALTER TABLE gameplayers ADD COLUMN screenshotcmd text NOT NULL default ''; ", 327 "ALTER TABLE gameplayers ADD COLUMN screenshotenabled tinyint(1) NOT NULL default '0'; ", 328 "" 329 }; 323 330 331 if (!performActualUpdate(updates, "1013", dbver)) 332 return false; 333 } 324 334 325 335 336 337 338 326 339 return true; 327 340 } -
mythgame/mythgame/main.cpp
33 33 settings.exec(); 34 34 } 35 35 36 if (sel == "game_players")36 else if (sel == "game_players") 37 37 { 38 38 MythGamePlayerEditor mgpe; 39 39 mgpe.exec(); … … 42 42 { 43 43 GameHandler::processAllGames(); 44 44 } 45 if (sel == "clear_game_data") 45 46 else if (sel == "clear_game_data") 46 47 { 47 48 GameHandler::clearAllGameData(); 48 49 } 49 50 51 else if (sel == "generate_screenshots") 52 { 53 GameHandler myHandler; 54 myHandler.generateScreenshots(); 55 } 56 50 57 } 51 58 52 59 void runMenu(QString which_menu) -
mythgame/mythgame/gametree.cpp
136 136 137 137 m_gameTree = new GenericTree("game root", 0, false); 138 138 139 timer = new QTimer( this ); 140 connect( timer, SIGNAL(timeout()), SLOT(showImageTimeout()) ); 141 139 142 wireUpTheme(); 140 143 // create system filter to only select games where handlers are present 141 144 QString systemFilter; … … 251 254 if (romInfo->ImagePath()) 252 255 { 253 256 m_gameImage->SetImage(romInfo->ImagePath()); 254 m_gameImage->LoadImage(); 257 if ( timer->isActive() ) 258 timer->changeInterval(300); 259 else 260 timer->start(300, true); 255 261 } 256 262 } 257 263 } 258 264 else 259 265 { // Otherwise use some defaults. 266 timer->stop(); 260 267 m_gameImage->SetImage(""); 261 268 m_gameTitle->SetText(""); 262 269 m_gameSystem->SetText("Unknown"); … … 267 274 268 275 } 269 276 277 void GameTree::showImageTimeout(void) 278 { 279 m_gameImage->LoadImage(); 280 } 281 270 282 QString getElement(QStringList list, int pos) 271 283 { 272 284 int curpos = 0; -
mythgame/mythgame/gamesettings.cpp
76 76 return gc; 77 77 } 78 78 79 static HostLineEdit *GameScreenshotCmd() 80 { 81 HostLineEdit *gc = new HostLineEdit("GameScreenshotCmd"); 82 gc->setLabel(QObject::tr("Screenshot Command")); 83 gc->setValue("/usr/bin/scrot --quality 1 \"%p.png\""); 84 gc->setHelpText(QObject::tr("Programm wich generate Screenshots " 85 "when the Rom ist started in Background " 86 "use %s for romname and %p for the imagename without extension.")); 87 return gc; 88 } 79 89 90 static HostLineEdit *GameScreenshotTime() 91 { 92 HostLineEdit *gc = new HostLineEdit("GameScreenshotTime"); 93 gc->setLabel(QObject::tr("Screenshot Timeout:")); 94 gc->setValue("10"); 95 gc->setHelpText(QObject::tr("Enter Time (in seconds) after wich a Screenshot is taken")); 96 return gc; 97 } 98 80 99 MythGameGeneralSettings::MythGameGeneralSettings() 81 100 { 82 101 VerticalConfigurationGroup *general = new VerticalConfigurationGroup(false); … … 87 106 general->addChild(GameRemovalPrompt()); 88 107 general->addChild(GameShowFileNames()); 89 108 109 VerticalConfigurationGroup *screenshot = new VerticalConfigurationGroup(false); 110 screenshot->setLabel(QObject::tr("MythGame Settings -- Screenshots")); 111 screenshot->addChild(GameScreenshotCmd()); 112 screenshot->addChild(GameScreenshotTime()); 113 90 114 addChild(general); 115 addChild(screenshot); 91 116 92 117 } 93 118 … … 183 208 }; 184 209 }; 185 210 211 class GenerateScreenshots: virtual public MGSetting, virtual public CheckBoxSetting { 212 public: 213 GenerateScreenshots(const MythGamePlayerSettings& parent): 214 MGSetting(parent, "screenshotenabled") { 215 setLabel(QObject::tr("Generation of SCreenshots Enabled")); 216 setHelpText(QObject::tr("This Setting means that this Gameplayer is included in the generation of Screenshots.")); 217 }; 218 }; 219 220 class GenerateScreenshotsCmd: virtual public MGSetting, virtual public LineEditSetting { 221 public: 222 GenerateScreenshotsCmd(const MythGamePlayerSettings& parent): 223 MGSetting(parent, "screenshotcmd") { 224 setLabel(QObject::tr("Screenshot Command")); 225 setHelpText(QObject::tr("If you want another Command then the global to Generate Screenshots, Enter it here!")); 226 }; 227 }; 228 186 229 MythGamePlayerSettings::MythGamePlayerSettings() 187 230 { 188 231 // must be first … … 198 241 group->addChild(new WorkingDirPath(*this)); 199 242 group->addChild(new Extensions(*this)); 200 243 group->addChild(new AllowMultipleRoms(*this)); 244 group->addChild(new GenerateScreenshots(*this)); 245 group->addChild(new GenerateScreenshotsCmd(*this)); 201 246 addChild(group); 202 247 }; 203 248