From 1a57f9488f74270a4754f13f94b72a663ec3b722 Mon Sep 17 00:00:00 2001 From: BreadFish64 Date: Thu, 19 Apr 2018 19:56:24 -0500 Subject: [PATCH] citra_qt: support multiple game directories --- dist/qt_themes/default/default.qrc | 12 + .../default/icons/256x256/plus_folder.png | Bin 0 -> 2551 bytes .../default/icons/48x48/bad_folder.png | Bin 0 -> 601 bytes dist/qt_themes/default/icons/48x48/chip.png | Bin 0 -> 456 bytes dist/qt_themes/default/icons/48x48/folder.png | Bin 0 -> 294 bytes dist/qt_themes/default/icons/48x48/plus.png | Bin 0 -> 316 bytes .../qt_themes/default/icons/48x48/sd_card.png | Bin 0 -> 311 bytes dist/qt_themes/default/icons/index.theme | 5 +- .../qdarkstyle/icons/256x256/plus_folder.png | Bin 0 -> 2300 bytes .../qdarkstyle/icons/48x48/bad_folder.png | Bin 0 -> 651 bytes .../qt_themes/qdarkstyle/icons/48x48/chip.png | Bin 0 -> 494 bytes .../qdarkstyle/icons/48x48/folder.png | Bin 0 -> 340 bytes .../qt_themes/qdarkstyle/icons/48x48/plus.png | Bin 0 -> 339 bytes .../qdarkstyle/icons/48x48/sd_card.png | Bin 0 -> 327 bytes dist/qt_themes/qdarkstyle/icons/index.theme | 7 +- dist/qt_themes/qdarkstyle/style.qrc | 6 + src/citra_qt/configuration/config.cpp | 41 ++- .../configuration/configure_general.cpp | 2 - .../configuration/configure_general.ui | 9 +- src/citra_qt/game_list.cpp | 335 ++++++++++++++---- src/citra_qt/game_list.h | 51 ++- src/citra_qt/game_list_p.h | 125 ++++++- src/citra_qt/main.cpp | 71 +++- src/citra_qt/main.h | 8 +- src/citra_qt/main.ui | 1 - src/citra_qt/ui_settings.h | 20 +- 26 files changed, 561 insertions(+), 132 deletions(-) create mode 100644 dist/qt_themes/default/icons/256x256/plus_folder.png create mode 100644 dist/qt_themes/default/icons/48x48/bad_folder.png create mode 100644 dist/qt_themes/default/icons/48x48/chip.png create mode 100644 dist/qt_themes/default/icons/48x48/folder.png create mode 100644 dist/qt_themes/default/icons/48x48/plus.png create mode 100644 dist/qt_themes/default/icons/48x48/sd_card.png create mode 100644 dist/qt_themes/qdarkstyle/icons/256x256/plus_folder.png create mode 100644 dist/qt_themes/qdarkstyle/icons/48x48/bad_folder.png create mode 100644 dist/qt_themes/qdarkstyle/icons/48x48/chip.png create mode 100644 dist/qt_themes/qdarkstyle/icons/48x48/folder.png create mode 100644 dist/qt_themes/qdarkstyle/icons/48x48/plus.png create mode 100644 dist/qt_themes/qdarkstyle/icons/48x48/sd_card.png diff --git a/dist/qt_themes/default/default.qrc b/dist/qt_themes/default/default.qrc index a524a17e7..974079e78 100644 --- a/dist/qt_themes/default/default.qrc +++ b/dist/qt_themes/default/default.qrc @@ -12,6 +12,18 @@ icons/16x16/lock.png + icons/48x48/bad_folder.png + + icons/48x48/chip.png + + icons/48x48/folder.png + + icons/48x48/plus.png + + icons/48x48/sd_card.png + icons/256x256/citra.png + + icons/256x256/plus_folder.png diff --git a/dist/qt_themes/default/icons/256x256/plus_folder.png b/dist/qt_themes/default/icons/256x256/plus_folder.png new file mode 100644 index 0000000000000000000000000000000000000000..5822f34c59b26fe6d0f397a2db0ec0a449046fe5 GIT binary patch literal 2551 zcmbtWdo8tX!N|IX;7680@zIG5c zF7|Ko&7C-xK%8G98i$Wajt1~}yxEzv7;IETQnXoOa!k3%PFoJdp$i-_X=6M%I;BEY|YK$jHx#o*ACR{bc#7YE&{lbATS!ND-bWFE96Yr?BCh zCksf5;VCJrT(3H84%r*Uw)vTJtL7#m{f=?o66ye3Y|&?p)*yy8NrEh;1>}h!?(~oL zF=#zKRVBs)d*v7YR*O1Mmp{*=Q>#js=Wdd>aAhCb+uNb-a@)B75{O*vU?9jDdzf$Y z@nk2bXW?m~0i)Ai*@rc*(2QXdq}(h(RMC*n@po{t6apw=#Ez2{Ck@1jU{Z>pH>4(v*L@ zWCFu)Bik_;i3H{9f_soY9;0ILoYoau)r45p3C1&lA)9E;#(AV(*ah7Sm8bY3=y(tY zO{lepTB!JC8mJT3TmWL9GN8T#1Sl8)PT>$h`9}b_v<=X=PyirS&+rOt5sx+#8ZbdB z5>p8cM==b^i1Os_R(l0 zit6K=xHA9vS5~EV!)%Nr#2JX3B>AR|)3?5V!?&|+1Do7+b%7kz2S6)nJp{whsqo>F zJNALeknm@Bi_NUsbjn4RZ90DLTHaAcbf`k}8?Fqiy<``2rzbE{euflugSMf`xi;Vg zl%86w(nQYo1OkxowZ*tI=G*0J_J3UU&z$|kJN&oC6b?MRu%W4mA03q8$&4=YVrguo z*A~NL3E7&HMJp8Y9{E!lz3n|rXw#1?+3p&W39XHcoD zoPB?HIoCP88La(kmlL+9m}!pS-Fw^nNvj`@!WWF9nieCrtAS$cS@SYC=A#aN-dT%cL@H(VXK89HVz1`>Nw>a% z1OHOIZ$T2@^7k$dDCh&jOZlbZNRT=a!53vt4T>GT!?ldj##@cRaFUUqc)LO1XoBgY!jakGJhv31N=>UNri|8siL8ffXts|7{7GbA-_R zM%hW-<=90JrUS~m>h#oDkvRY5ZsJ)EI6O74#@bj=W5;Ov30Fd^`VNH_*O0U1d1B4A zfALXvvUAv>x)pU`T&y3f2L=6w-2cbR$7SyJ2?%fSkgExg{_hstUV}ghJ4i*|^_<*{xwP4;rJJ>=VlgGNu zS`$>JW=Uw3=b0v2uk}{gAkU@&mTyG)jlZ%P!u$ny6IlRrI$H{O&dgk^Ie(ozLe=@l zGNo5jY6?x_ z&Bk8GL1HDJ;@C6NdTkuw5il>KbqO`R@Ip0-(eNQQFYx{P`;tF`UxBCF&cJ$Z@Bm+cUw~Ig zoaP444ct&V{q?hqT=)){AYm?$3%?TXySdNYp)l63W*W$;@TTbi4r9? zA#I|Zs+_izNX+>>fyl(8B{CLlzCZ*(Es5jO=6fRmNcMtGJZG08^OS+Ir@#g7uvYGWi(^e{JADh(ux z9jDcGK2xH|51N##k5q{~0n4*ZqC~ntfrD9!M4CVecwuZwV!S{}cwvs1#5jQ|;Dx#R zB=iDP!V7b@C3FHc;DxzWx8mo^!-Ts^^EPl7+j}><2F`PUACNc^`!ZBBZDOIWPIH96 ngi6BQ`-g6K?|(ITM5Xuvo*IKgQXns500000NkvXXu0mjfgGc(| literal 0 HcmV?d00001 diff --git a/dist/qt_themes/default/icons/48x48/chip.png b/dist/qt_themes/default/icons/48x48/chip.png new file mode 100644 index 0000000000000000000000000000000000000000..d07a85aca46a207fe529ac042a50c62c0b4bb5d8 GIT binary patch literal 456 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$QVa}?uAVNA zAsLNtX9VUo8}K;9Z!ZhKp}Okt8?N6s`L1jZb-E?^qjA0G<#!i-OXN+JnwU5Zkkh>hnjZ zyLz1&EH{|H+g|iHd+YAjeGGB3$I@D_w+Wv*zv`NUo4Nh%ol$2E`nq0cADyx$Z_g@8 ziR7!<512J1=amI}ZJarEp?UD7C+m7ck{-WW-hA3Fp#0aB&pFR8h#z?G5MNtoHAB-R zthLN!wx7qgN3ZQxU04;Q;R$kzXjgBT;=}IKf(NH{cLbQ&i6lZ{y>!~=Rd~XN3LJk&iE}980rk3u6{1-oD!MO=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0wEJzX3_ zG8*6B^yX@I5OBTde!^^%{O13nF5*dQnFbG*H_NV5`|i+~!T-wf>k=Oo&)&O}c|4Ex zzM5PT(7!rsmj2gyO=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0vJJzX3_ zG8*5`G~{bB;9(Izayj?|=d9|es88(c6hvcGm{vW4t_NTMu#(^ zpCZlAFl=)^d&NaOvQR9-mW@}=cO!eAQU02{8%%`~lo`zs#C{gFH|5`3K2N<7rTXrh zx8>xQfg*A|pVlP^cIb0Nt*YSpJ>B|4=Db6Fn$f+g>tc_pUYk9mm*s{>0}?Ua!DycC nG4BM!d3&e5+aKBbqE-L&@s;+EX1>`3^aO*atDnm{r-UW|DM4-g literal 0 HcmV?d00001 diff --git a/dist/qt_themes/default/icons/48x48/sd_card.png b/dist/qt_themes/default/icons/48x48/sd_card.png new file mode 100644 index 0000000000000000000000000000000000000000..3226347e2798fe5c068018656c4121f2ef3e002b GIT binary patch literal 311 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0vpJY5_^ zG8*6BJjmB%AmDm&`NMGEDIcc)o04~d_gEY2mXkj6$Et;zRvT@9bj-_P*X||LKi(=? z#c?B6<>s><=POQ}tIXcbv2`_Ly2DYRe4v-X94mt(?CbQZml=#_qnJ<0p89d;&HH_g zhchh~zI<5BWuo^z{m7!5@BjWXH}IM@{q?tO#_35vG?RXOWj0#MqyN=bc;46A|A)U= jy{Plp<;Ktdrh@tZtyyXD;!oT=7z$p<6S0SIpU zeL?9-C(YDGs|^2R8AnKjjLi776Cg7)b6a9+a(Y5M`NTF-8nI03Z4H19CD3nQSXTK* zQEZRsj2$vBC!QM3*m2PHOi9lcJ)4odTJtYfux)pGu5~;qp zw|F7fXWCmx>4O5VZ2Ujwo#s-x0YTz4=@nE~3QPNl&ffcHX>Y52SSwj8)EBp{;3Cl@r+^qburF!ogAI~`7KGa=@l9gChWLlN4J7q`Jxl_kwni4o&z2P7{+tB0cd^Z$ijVp=^;+47#OgL$*Zh0W1Iq)tBfwcgZvhQrM6)CL_Xx*O3%l zF^)GE7>VjnBfW|98y_P-`C;&+a_q`P_A8#&wLd)l$uN8Z>^v@M5d^SV7Oc0Y!Y4{tWw0DgLiZ7OsOVkz z^+XA7(E9kf7!+F*qbV(BT4=M0i7rzXvmHMPmJrM&7LhQzSzMa}%%uJro0SP-ir_{O^XL1(t6vDKv7_SXtxIuW zbha}aDw_3_)v7Ob(yH3$XA7m;Pz@^vq|B^SGk+^7gie~7h&8``uq--I^v1KH@$s&t zIN;QuTODnv)Uh|!Pt1FjOl~QoyRGe(eeW7M(oV?xzV~_e@Jo48@`#;>(wOt#3cT*hbn#*Gh zCFxqi^LrlVb9rT>X840zaY||Ivr+Vsvi<9xgY#k$a$k4I?qAv5kkNknX!qF#;;&A)s}`D9{l5LI5T4ERt%-y4$tohQ5B@+DhtK#>QUZQ>G$W{9Pnn zNAb4n?WW$Z2Qe2)zQd+Fk~M}09t00WDRr|F{FIGzXK!Z%QDLN*7(6gr0a8;&l&((~ zfWtRFvb>=)R|xMHOnz2|%YuxcwXX>i`Z?={U4PlVv3`Wd5c>1&t~#?l0bo(g)wS{> zw>)6L4->ysQEp$csFAFP1hQJ}6o9;wY$AJ~SP^O3u$=y=202pK&UvdY53&ZwKUvAc bp3wn2fP830wdAhuR6wAAu;0D?acBPt#GL04 literal 0 HcmV?d00001 diff --git a/dist/qt_themes/qdarkstyle/icons/48x48/bad_folder.png b/dist/qt_themes/qdarkstyle/icons/48x48/bad_folder.png new file mode 100644 index 0000000000000000000000000000000000000000..f7f38308988e4c08ce5fdc3cebd41fe6b3bb6d48 GIT binary patch literal 651 zcmV;60(AX}P)8UIQMebG~Z~8W?X`N6(c)a+^Zw zwNuNBc&J?fwz-WCJ^h!hv1vnVp@_C``;X6Gpb0>1RKupbA^Ud?PFoj?V=Iq4n%7C;4TJf#8_F?@#v z`RB^GfExU1fGX5a7qNO^s(^cnvz^9pyqhS#Qz(YhBV0?G9I3+TOremYL@h~XcH8mY zM$$!~@2#0#hWP0s`wEliIu>kq_w22r>rGCMDp#&SdY`? zA6Yhxbqi%*fspO=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0u)JzX3_ zG8*6BaO7%okU0AB|CH_p%2zn8+~bZPE}3_3qWA}vwYRQhD>g+gS@217k32`S)rWb; zn+4CD$?=+0rdEvOtc{8@O#%+YYsf;5_!wc9Tu2wY8>5Q Y-hZ-ioric+Jzopr0Qu90HUIzs literal 0 HcmV?d00001 diff --git a/dist/qt_themes/qdarkstyle/icons/48x48/plus.png b/dist/qt_themes/qdarkstyle/icons/48x48/plus.png new file mode 100644 index 0000000000000000000000000000000000000000..16cc8b4f44d52009d4a3f4c9d46f5bb0e20babcf GIT binary patch literal 339 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0u)JY5_^ zG8*6BbmVI?5NLh4@}X2!l-S-D>HaqF9f#jLiMc75c-1D{o4(=YB4d5u$$lLMo6j=x zUSPWWW2?jBcdI2P%slmKUl-$FpN4&IYeSNQ8*V0P=El9>^0jUMGlnd_1qi~7(|}J| zQX*~M5!Y#5wY%=$@Lrap@yOElZRqcN@1NB2l?WEb+1qqhd%gU$>qC9Hf>NIS`$c!E z@^cD0wIlW%nb&z$#^EgE6$FvRD#3MqUzqlRtp&OBEq>*PZDy`yczi-rX+hv3f1uwO NJYD@<);T3K0RY^^g3SN` literal 0 HcmV?d00001 diff --git a/dist/qt_themes/qdarkstyle/icons/48x48/sd_card.png b/dist/qt_themes/qdarkstyle/icons/48x48/sd_card.png new file mode 100644 index 0000000000000000000000000000000000000000..9052ae794eb69854ec13db86d5ceb908b673b76c GIT binary patch literal 327 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0vVJY5_^ zG8*6B4CHDy5NLV0q+(6n@(W)1FPGjDKR#W=)oZfJZpqf44gwc=gTe~ HDWM4f$mV`> literal 0 HcmV?d00001 diff --git a/dist/qt_themes/qdarkstyle/icons/index.theme b/dist/qt_themes/qdarkstyle/icons/index.theme index 558ece40b..d1e12f3ef 100644 --- a/dist/qt_themes/qdarkstyle/icons/index.theme +++ b/dist/qt_themes/qdarkstyle/icons/index.theme @@ -2,10 +2,13 @@ Name=qdarkstyle Comment=dark theme Inherits=default -Directories=16x16,256x256 +Directories=16x16,48x48,256x256 [16x16] Size=16 - + +[48x48] +Size=48 + [256x256] Size=256 \ No newline at end of file diff --git a/dist/qt_themes/qdarkstyle/style.qrc b/dist/qt_themes/qdarkstyle/style.qrc index 54a96b680..c2c14c28a 100644 --- a/dist/qt_themes/qdarkstyle/style.qrc +++ b/dist/qt_themes/qdarkstyle/style.qrc @@ -2,6 +2,12 @@ icons/index.theme icons/16x16/lock.png + icons/48x48/bad_folder.png + icons/48x48/chip.png + icons/48x48/folder.png + icons/48x48/plus.png + icons/48x48/sd_card.png + icons/256x256/plus_folder.png rc/up_arrow_disabled.png diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index bdb296659..3e808dfa4 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -202,8 +202,34 @@ void Config::ReadValues() { qt_config->beginGroup("Paths"); UISettings::values.roms_path = qt_config->value("romsPath").toString(); UISettings::values.symbols_path = qt_config->value("symbolsPath").toString(); - UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); - UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); + UISettings::values.game_dir_deprecated = qt_config->value("gameListRootDir", ".").toString(); + UISettings::values.game_dir_deprecated_deepscan = + qt_config->value("gameListDeepScan", false).toBool(); + int size = qt_config->beginReadArray("gamedirs"); + for (int i = 0; i < size; ++i) { + qt_config->setArrayIndex(i); + UISettings::GameDir game_dir; + game_dir.path = qt_config->value("path").toString(); + game_dir.deep_scan = qt_config->value("deep_scan", false).toBool(); + game_dir.expanded = qt_config->value("expanded", true).toBool(); + UISettings::values.game_dirs.append(game_dir); + } + qt_config->endArray(); + // create NAND and SD card directories if empty, these are not removable through the UI, also + // carries over old game list settings if present + if (UISettings::values.game_dirs.isEmpty()) { + UISettings::GameDir game_dir; + game_dir.path = "INSTALLED"; + game_dir.expanded = true; + UISettings::values.game_dirs.append(game_dir); + game_dir.path = "SYSTEM"; + UISettings::values.game_dirs.append(game_dir); + if (UISettings::values.game_dir_deprecated != ".") { + game_dir.path = UISettings::values.game_dir_deprecated; + game_dir.deep_scan = UISettings::values.game_dir_deprecated_deepscan; + UISettings::values.game_dirs.append(game_dir); + } + } UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); UISettings::values.language = qt_config->value("language", "").toString(); qt_config->endGroup(); @@ -378,8 +404,15 @@ void Config::SaveValues() { qt_config->beginGroup("Paths"); qt_config->setValue("romsPath", UISettings::values.roms_path); qt_config->setValue("symbolsPath", UISettings::values.symbols_path); - qt_config->setValue("gameListRootDir", UISettings::values.gamedir); - qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); + qt_config->beginWriteArray("gamedirs"); + for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) { + qt_config->setArrayIndex(i); + const auto& game_dir = UISettings::values.game_dirs.at(i); + qt_config->setValue("path", game_dir.path); + qt_config->setValue("deep_scan", game_dir.deep_scan); + qt_config->setValue("expanded", game_dir.expanded); + } + qt_config->endArray(); qt_config->setValue("recentFiles", UISettings::values.recent_files); qt_config->setValue("language", UISettings::values.language); qt_config->endGroup(); diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index ad008a011..0bdeeeb3d 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -44,7 +44,6 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) ConfigureGeneral::~ConfigureGeneral() {} void ConfigureGeneral::setConfiguration() { - ui->toggle_deepscan->setChecked(UISettings::values.gamedir_deepscan); ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); ui->toggle_cpu_jit->setChecked(Settings::values.use_cpu_jit); @@ -60,7 +59,6 @@ void ConfigureGeneral::setConfiguration() { } void ConfigureGeneral::applyConfiguration() { - UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked(); UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); UISettings::values.theme = ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString(); diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index c2bf24b52..7a949979a 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -7,7 +7,7 @@ 0 0 345 - 493 + 504 @@ -31,13 +31,6 @@ - - - - Search sub-directories for games - - - diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 14e647559..e01c302b7 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -66,6 +66,7 @@ bool GameList::SearchField::KeyReleaseEater::eventFilter(QObject* obj, QEvent* e case Qt::Key_Enter: { if (gamelist->search_field->visible == 1) { QString file_path = gamelist->getLastFilterResultItem(); + // To avoid loading error dialog loops while confirming them using enter // Also users usually want to run a diffrent game after closing one gamelist->search_field->edit_filter->setText(""); @@ -171,6 +172,15 @@ bool GameList::containsAllWords(QString haystack, QString userinput) { [haystack](QString s) { return haystack.contains(s); }); } +// Syncs the expanded state of Game Directories with settings to persist across sessions +void GameList::onItemExpanded(const QModelIndex& item) { + GameListItemType type = item.data(GameListItem::TypeRole).value(); + if (type == GameListItemType::CustomDir || type == GameListItemType::InstalledDir || + type == GameListItemType::SystemDir) + item.data(GameListDir::GameDirRole).value()->expanded = + tree_view->isExpanded(item); +} + // Event in order to filter the gamelist after editing the searchfield void GameList::onTextChanged(const QString& newText) { int folderCount = tree_view->model()->rowCount(); @@ -226,6 +236,31 @@ void GameList::onTextChanged(const QString& newText) { } } +void GameList::onUpdateThemedIcons() { + for (int i = 0; i < item_model->invisibleRootItem()->rowCount(); i++) { + QStandardItem* child = item_model->invisibleRootItem()->child(i); + + switch (child->data(GameListItem::TypeRole).value()) { + case GameListItemType::InstalledDir: + child->setData(QIcon::fromTheme("sd_card").pixmap(48), Qt::DecorationRole); + break; + case GameListItemType::SystemDir: + child->setData(QIcon::fromTheme("chip").pixmap(48), Qt::DecorationRole); + break; + case GameListItemType::CustomDir: { + const UISettings::GameDir* game_dir = + child->data(GameListDir::GameDirRole).value(); + QString icon_name = QFileInfo::exists(game_dir->path) ? "folder" : "bad_folder"; + child->setData(QIcon::fromTheme(icon_name).pixmap(48), Qt::DecorationRole); + break; + } + case GameListItemType::AddDir: + child->setData(QIcon::fromTheme("plus").pixmap(48), Qt::DecorationRole); + break; + } + } +} + void GameList::onFilterCloseClicked() { main_window->filterBarSetChecked(false); } @@ -257,12 +292,16 @@ GameList::GameList(GMainWindow* parent) : QWidget{parent} { item_model->setHeaderData(COLUMN_REGION, Qt::Horizontal, "Region"); item_model->setHeaderData(COLUMN_FILE_TYPE, Qt::Horizontal, "File type"); item_model->setHeaderData(COLUMN_SIZE, Qt::Horizontal, "Size"); + item_model->setSortRole(GameListItemPath::TitleRole); + connect(main_window, &GMainWindow::UpdateThemedIcons, this, &GameList::onUpdateThemedIcons); connect(tree_view, &QTreeView::activated, this, &GameList::ValidateEntry); connect(tree_view, &QTreeView::customContextMenuRequested, this, &GameList::PopupContextMenu); + connect(tree_view, &QTreeView::expanded, this, &GameList::onItemExpanded); + connect(tree_view, &QTreeView::collapsed, this, &GameList::onItemExpanded); - // We must register all custom types with the Qt Automoc system so that we are able to use it - // with signals/slots. In this case, QList falls under the umbrells of custom types. + // We must register all custom types with the Qt Automoc system so that we are able to use + // it with signals/slots. In this case, QList falls under the umbrells of custom types. qRegisterMetaType>("QList"); layout->setContentsMargins(0, 0, 0, 0); @@ -290,27 +329,57 @@ void GameList::clearFilter() { search_field->clear(); } -void GameList::AddEntry(const QList& entry_items) { +void GameList::AddDirEntry(GameListDir* entry_items) { item_model->invisibleRootItem()->appendRow(entry_items); + tree_view->setExpanded( + entry_items->index(), + entry_items->data(GameListDir::GameDirRole).value()->expanded); +} + +void GameList::AddEntry(const QList& entry_items, GameListDir* parent) { + parent->appendRow(entry_items); } void GameList::ValidateEntry(const QModelIndex& item) { - // We don't care about the individual QStandardItem that was selected, but its row. - int row = item_model->itemFromIndex(item)->row(); - QStandardItem* child_file = item_model->invisibleRootItem()->child(row, COLUMN_NAME); - QString file_path = child_file->data(GameListItemPath::FullPathRole).toString(); + auto selected = item.sibling(item.row(), 0); - if (file_path.isEmpty()) - return; - std::string std_file_path(file_path.toStdString()); - if (!FileUtil::Exists(std_file_path) || FileUtil::IsDirectory(std_file_path)) - return; - // Users usually want to run a diffrent game after closing one - search_field->clear(); - emit GameChosen(file_path); + switch (selected.data(GameListItem::TypeRole).value()) { + case GameListItemType::Game: { + QString file_path = selected.data(GameListItemPath::FullPathRole).toString(); + if (file_path.isEmpty()) + return; + QFileInfo file_info(file_path); + if (!file_info.exists() || file_info.isDir()) + return; + // Users usually want to run a different game after closing one + search_field->clear(); + emit GameChosen(file_path); + break; + } + case GameListItemType::AddDir: + emit AddDirectory(); + break; + } +} + +bool GameList::isEmpty() { + for (int i = 0; i < item_model->rowCount(); i++) { + const QStandardItem* child = item_model->invisibleRootItem()->child(i); + GameListItemType type = static_cast(child->type()); + if (!child->hasChildren() && + (type == GameListItemType::InstalledDir || type == GameListItemType::SystemDir)) { + item_model->invisibleRootItem()->removeRow(child->row()); + i--; + }; + } + return !item_model->invisibleRootItem()->hasChildren(); } void GameList::DonePopulating(QStringList watch_list) { + emit ShowList(!isEmpty()); + + item_model->invisibleRootItem()->appendRow(new GameListAddDir()); + // Clear out the old directories to watch for changes and add the new ones auto watch_dirs = watcher->directories(); if (!watch_dirs.isEmpty()) { @@ -346,12 +415,25 @@ void GameList::PopupContextMenu(const QPoint& menu_location) { if (!item.isValid()) return; - int row = item_model->itemFromIndex(item)->row(); - QStandardItem* child_file = item_model->invisibleRootItem()->child(row, COLUMN_NAME); - u64 program_id = child_file->data(GameListItemPath::ProgramIdRole).toULongLong(); - + auto selected = item.sibling(item.row(), 0); QMenu context_menu; + switch (selected.data(GameListItem::TypeRole).value()) { + case GameListItemType::Game: + AddGamePopup(context_menu, selected.data(GameListItemPath::ProgramIdRole).toULongLong()); + break; + case GameListItemType::CustomDir: + AddPermDirPopup(context_menu, selected); + AddCustomDirPopup(context_menu, selected); + break; + case GameListItemType::InstalledDir: + case GameListItemType::SystemDir: + AddPermDirPopup(context_menu, selected); + break; + } + context_menu.exec(tree_view->viewport()->mapToGlobal(menu_location)); +} +void GameList::AddGamePopup(QMenu& context_menu, u64 program_id) { QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location")); QAction* open_application_location = context_menu.addAction(tr("Open Application Location")); QAction* open_update_location = context_menu.addAction(tr("Open Update Data Location")); @@ -370,16 +452,81 @@ void GameList::PopupContextMenu(const QPoint& menu_location) { }); navigate_to_gamedb_entry->setVisible(it != compatibility_list.end()); - connect(open_save_location, &QAction::triggered, - [&]() { emit OpenFolderRequested(program_id, GameListOpenTarget::SAVE_DATA); }); - connect(open_application_location, &QAction::triggered, - [&]() { emit OpenFolderRequested(program_id, GameListOpenTarget::APPLICATION); }); - connect(open_update_location, &QAction::triggered, - [&]() { emit OpenFolderRequested(program_id, GameListOpenTarget::UPDATE_DATA); }); - connect(navigate_to_gamedb_entry, &QAction::triggered, - [&]() { emit NavigateToGamedbEntryRequested(program_id, compatibility_list); }); + connect(open_save_location, &QAction::triggered, [this, program_id] { + emit OpenFolderRequested(program_id, GameListOpenTarget::SAVE_DATA); + }); + connect(open_application_location, &QAction::triggered, [this, program_id] { + emit OpenFolderRequested(program_id, GameListOpenTarget::APPLICATION); + }); + connect(open_update_location, &QAction::triggered, [this, program_id] { + emit OpenFolderRequested(program_id, GameListOpenTarget::UPDATE_DATA); + }); + connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() { + emit NavigateToGamedbEntryRequested(program_id, compatibility_list); + }); +}; - context_menu.exec(tree_view->viewport()->mapToGlobal(menu_location)); +void GameList::AddCustomDirPopup(QMenu& context_menu, QModelIndex selected) { + UISettings::GameDir& game_dir = + *selected.data(GameListDir::GameDirRole).value(); + + QAction* deep_scan = context_menu.addAction(tr("Scan Subfolders")); + QAction* delete_dir = context_menu.addAction(tr("Remove Game Directory")); + + deep_scan->setCheckable(true); + deep_scan->setChecked(game_dir.deep_scan); + + connect(deep_scan, &QAction::triggered, [this, &game_dir] { + game_dir.deep_scan = !game_dir.deep_scan; + PopulateAsync(UISettings::values.game_dirs); + }); + connect(delete_dir, &QAction::triggered, [this, &game_dir, selected] { + UISettings::values.game_dirs.removeOne(game_dir); + item_model->invisibleRootItem()->removeRow(selected.row()); + }); +} + +void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { + UISettings::GameDir& game_dir = + *selected.data(GameListDir::GameDirRole).value(); + + QAction* move_up = context_menu.addAction(tr(u8"\U000025b2 Move Up")); + QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down ")); + QAction* open_directory_location = context_menu.addAction(tr("Open Directory Location")); + + int row = selected.row(); + + move_up->setEnabled(row > 0); + move_down->setEnabled(row < item_model->rowCount() - 2); + + connect(move_up, &QAction::triggered, [this, selected, row, &game_dir] { + // find the indices of the items in settings and swap them + UISettings::values.game_dirs.swap( + UISettings::values.game_dirs.indexOf(game_dir), + UISettings::values.game_dirs.indexOf(*selected.sibling(selected.row() - 1, 0) + .data(GameListDir::GameDirRole) + .value())); + // move the treeview items + QList item = item_model->takeRow(row); + item_model->invisibleRootItem()->insertRow(row - 1, item); + tree_view->setExpanded(selected, game_dir.expanded); + }); + + connect(move_down, &QAction::triggered, [this, selected, row, &game_dir] { + // find the indices of the items in settings and swap them + UISettings::values.game_dirs.swap( + UISettings::values.game_dirs.indexOf(game_dir), + UISettings::values.game_dirs.indexOf(*selected.sibling(selected.row() + 1, 0) + .data(GameListDir::GameDirRole) + .value())); + // move the treeview items + QList item = item_model->takeRow(row); + item_model->invisibleRootItem()->insertRow(row + 1, item); + tree_view->setExpanded(selected, game_dir.expanded); + }); + + connect(open_directory_location, &QAction::triggered, + [this, game_dir] { emit OpenDirectory(game_dir.path); }); } void GameList::LoadCompatibilityList() { @@ -428,14 +575,7 @@ QStandardItemModel* GameList::GetModel() const { return item_model; } -void GameList::PopulateAsync(const QString& dir_path, bool deep_scan) { - if (!FileUtil::Exists(dir_path.toStdString()) || - !FileUtil::IsDirectory(dir_path.toStdString())) { - NGLOG_ERROR(Frontend, "Could not find game list folder at {}", dir_path.toStdString()); - search_field->setFilterResult(0, 0); - return; - } - +void GameList::PopulateAsync(QList& game_dirs) { tree_view->setEnabled(false); // Delete any rows that might already exist if we're repopulating item_model->removeRows(0, item_model->rowCount()); @@ -443,13 +583,15 @@ void GameList::PopulateAsync(const QString& dir_path, bool deep_scan) { emit ShouldCancelWorker(); - GameListWorker* worker = new GameListWorker(dir_path, deep_scan, compatibility_list); + GameListWorker* worker = new GameListWorker(game_dirs, compatibility_list); connect(worker, &GameListWorker::EntryReady, this, &GameList::AddEntry, Qt::QueuedConnection); + connect(worker, &GameListWorker::DirEntryReady, this, &GameList::AddDirEntry, + Qt::QueuedConnection); connect(worker, &GameListWorker::Finished, this, &GameList::DonePopulating, Qt::QueuedConnection); - // Use DirectConnection here because worker->Cancel() is thread-safe and we want it to cancel - // without delay. + // Use DirectConnection here because worker->Cancel() is thread-safe and we want it to + // cancel without delay. connect(this, &GameList::ShouldCancelWorker, worker, &GameListWorker::Cancel, Qt::DirectConnection); @@ -481,15 +623,17 @@ static bool HasSupportedFileExtension(const std::string& file_name) { } void GameList::RefreshGameDirectory() { - if (!UISettings::values.gamedir.isEmpty() && current_worker != nullptr) { + if (!UISettings::values.game_dirs.isEmpty() && current_worker != nullptr) { NGLOG_INFO(Frontend, "Change detected in the games directory. Reloading game list."); - PopulateAsync(UISettings::values.gamedirs); + PopulateAsync(UISettings::values.game_dirs); } } -void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion) { - const auto callback = [this, recursion](unsigned* num_entries_out, const std::string& directory, - const std::string& virtual_name) -> bool { +void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion, + GameListDir* parent_dir) { + const auto callback = [this, recursion, parent_dir](unsigned* num_entries_out, + const std::string& directory, + const std::string& virtual_name) -> bool { std::string physical_name = directory + DIR_SEP + virtual_name; if (stop_processing) @@ -539,17 +683,20 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign if (it != compatibility_list.end()) compatibility = it->second.first; - emit EntryReady({ - new GameListItemPath(QString::fromStdString(physical_name), smdh, program_id), - new GameListItemCompat(compatibility), - new GameListItemRegion(smdh), - new GameListItem( - QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))), - new GameListItemSize(FileUtil::GetSize(physical_name)), - }); + emit EntryReady( + { + new GameListItemPath(QString::fromStdString(physical_name), smdh, program_id), + new GameListItemCompat(compatibility), + new GameListItemRegion(smdh), + new GameListItem( + QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))), + new GameListItemSize(FileUtil::GetSize(physical_name)), + }, + parent_dir); + } else if (is_dir && recursion > 0) { watch_list.append(QString::fromStdString(physical_name)); - AddFstEntriesToGameList(physical_name, recursion - 1); + AddFstEntriesToGameList(physical_name, recursion - 1, parent_dir); } return true; @@ -560,27 +707,33 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign void GameListWorker::run() { stop_processing = false; - watch_list.append(dir_path); - watch_list.append(QString::fromStdString( - std::string(FileUtil::GetUserPath(D_SDMC_IDX).c_str()) + - "Nintendo " - "3DS/00000000000000000000000000000000/00000000000000000000000000000000/title/00040000")); - watch_list.append(QString::fromStdString( - std::string(FileUtil::GetUserPath(D_SDMC_IDX).c_str()) + - "Nintendo " - "3DS/00000000000000000000000000000000/00000000000000000000000000000000/title/0004000e")); - watch_list.append( - QString::fromStdString(std::string(FileUtil::GetUserPath(D_NAND_IDX).c_str()) + - "00000000000000000000000000000000/title/00040010")); - AddFstEntriesToGameList(dir_path.toStdString(), deep_scan ? 256 : 0); - AddFstEntriesToGameList( - std::string(FileUtil::GetUserPath(D_SDMC_IDX).c_str()) + - "Nintendo " - "3DS/00000000000000000000000000000000/00000000000000000000000000000000/title/00040000", - 2); - AddFstEntriesToGameList(std::string(FileUtil::GetUserPath(D_NAND_IDX).c_str()) + - "00000000000000000000000000000000/title/00040010", - 2); + for (UISettings::GameDir& game_dir : game_dirs) { + if (game_dir.path == "INSTALLED") { + QString path = QString(FileUtil::GetUserPath(D_SDMC_IDX).c_str()) + + "Nintendo " + "3DS/00000000000000000000000000000000/" + "00000000000000000000000000000000/title/00040000"; + watch_list.append(path); + GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir); + emit DirEntryReady({game_list_dir}); + AddFstEntriesToGameList(path.toStdString(), 2, game_list_dir); + } else if (game_dir.path == "SYSTEM") { + QString path = QString(FileUtil::GetUserPath(D_NAND_IDX).c_str()) + + "00000000000000000000000000000000/title/00040010"; + watch_list.append(path); + GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir); + emit DirEntryReady({game_list_dir}); + AddFstEntriesToGameList(std::string(FileUtil::GetUserPath(D_NAND_IDX).c_str()) + + "00000000000000000000000000000000/title/00040010", + 2, game_list_dir); + } else { + watch_list.append(game_dir.path); + GameListDir* game_list_dir = new GameListDir(game_dir); + emit DirEntryReady({game_list_dir}); + AddFstEntriesToGameList(game_dir.path.toStdString(), game_dir.deep_scan ? 256 : 0, + game_list_dir); + } + }; emit Finished(watch_list); } @@ -588,3 +741,37 @@ void GameListWorker::Cancel() { this->disconnect(); stop_processing = true; } + +GameListPlaceholder::GameListPlaceholder(GMainWindow* parent) : QWidget{parent} { + this->main_window = parent; + + connect(main_window, &GMainWindow::UpdateThemedIcons, this, + &GameListPlaceholder::onUpdateThemedIcons); + + layout = new QVBoxLayout; + image = new QLabel; + text = new QLabel; + layout->setAlignment(Qt::AlignCenter); + image->setPixmap(QIcon::fromTheme("plus_folder").pixmap(200)); + + text->setText(tr("Double-click to add a new folder to the game list ")); + QFont font = text->font(); + font.setPointSize(20); + text->setFont(font); + text->setAlignment(Qt::AlignHCenter); + image->setAlignment(Qt::AlignHCenter); + + layout->addWidget(image); + layout->addWidget(text); + setLayout(layout); +} + +GameListPlaceholder::~GameListPlaceholder() = default; + +void GameListPlaceholder::onUpdateThemedIcons() { + image->setPixmap(QIcon::fromTheme("plus_folder").pixmap(200)); +} + +void GameListPlaceholder::mouseDoubleClickEvent(QMouseEvent* event) { + emit GameListPlaceholder::AddDirectory(); +} diff --git a/src/citra_qt/game_list.h b/src/citra_qt/game_list.h index 96e2c46fd..f600f6ef8 100644 --- a/src/citra_qt/game_list.h +++ b/src/citra_qt/game_list.h @@ -8,13 +8,17 @@ #include #include #include "common/common_types.h" +#include "ui_settings.h" class GameListWorker; +class GameListDir; class GMainWindow; class QFileSystemWatcher; class QHBoxLayout; class QLabel; class QLineEdit; +template +class QList; class QModelIndex; class QStandardItem; class QStandardItemModel; @@ -39,12 +43,14 @@ public: class SearchField : public QWidget { public: - int visible; - int total; + explicit SearchField(GameList* parent = nullptr); + void setFilterResult(int visible, int total); void clear(); void setFocus(); - explicit SearchField(GameList* parent = nullptr); + + int visible; + int total; private: class KeyReleaseEater : public QObject { @@ -73,9 +79,10 @@ public: void clearFilter(); void setFilterFocus(); void setFilterVisible(bool visibility); + bool isEmpty(); void LoadCompatibilityList(); - void PopulateAsync(const QString& dir_path, bool deep_scan); + void PopulateAsync(QList& game_dirs); void SaveInterfaceLayout(); void LoadInterfaceLayout(); @@ -91,20 +98,30 @@ signals: void NavigateToGamedbEntryRequested( u64 program_id, std::unordered_map>& compatibility_list); + void OpenDirectory(QString directory); + void AddDirectory(); + void ShowList(bool show); private slots: + void onItemExpanded(const QModelIndex& item); void onTextChanged(const QString& newText); void onFilterCloseClicked(); + void onUpdateThemedIcons(); private: - void AddEntry(const QList& entry_items); + void AddDirEntry(GameListDir* entry_items); + void AddEntry(const QList& entry_items, GameListDir* parent); void ValidateEntry(const QModelIndex& item); void DonePopulating(QStringList watch_list); - void PopupContextMenu(const QPoint& menu_location); void RefreshGameDirectory(); bool containsAllWords(QString haystack, QString userinput); + void PopupContextMenu(const QPoint& menu_location); + void AddGamePopup(QMenu& context_menu, u64 program_id); + void AddCustomDirPopup(QMenu& context_menu, QModelIndex selected); + void AddPermDirPopup(QMenu& context_menu, QModelIndex selected); + SearchField* search_field; GMainWindow* main_window = nullptr; QVBoxLayout* layout = nullptr; @@ -116,3 +133,25 @@ private: }; Q_DECLARE_METATYPE(GameListOpenTarget); + +class GameListPlaceholder : public QWidget { + Q_OBJECT +public: + explicit GameListPlaceholder(GMainWindow* parent = nullptr); + ~GameListPlaceholder(); + +signals: + void AddDirectory(); + +private slots: + void onUpdateThemedIcons(); + +protected: + void mouseDoubleClickEvent(QMouseEvent* event) override; + +private: + GMainWindow* main_window = nullptr; + QVBoxLayout* layout = nullptr; + QLabel* image = nullptr; + QLabel* text = nullptr; +}; diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h index d39281f59..fbbeeb66b 100644 --- a/src/citra_qt/game_list_p.h +++ b/src/citra_qt/game_list_p.h @@ -8,17 +8,29 @@ #include #include #include +#include #include #include #include #include #include #include +#include "citra_qt/ui_settings.h" #include "citra_qt/util/util.h" #include "common/logging/log.h" #include "common/string_util.h" #include "core/loader/smdh.h" +enum class GameListItemType { + Game = QStandardItem::UserType + 1, + CustomDir = QStandardItem::UserType + 2, + InstalledDir = QStandardItem::UserType + 3, + SystemDir = QStandardItem::UserType + 4, + AddDir = QStandardItem::UserType + 5 +}; + +Q_DECLARE_METATYPE(GameListItemType); + /** * Gets the game icon from SMDH data. * @param smdh SMDH data @@ -125,8 +137,13 @@ const static inline std::map status_data = { class GameListItem : public QStandardItem { public: + // used to access type from item index + static const int TypeRole = Qt::UserRole + 1; + static const int SortRole = Qt::UserRole + 2; GameListItem() : QStandardItem() {} - GameListItem(const QString& string) : QStandardItem(string) {} + GameListItem(const QString& string) : QStandardItem(string) { + setData(string, SortRole); + } virtual ~GameListItem() override {} }; @@ -138,13 +155,14 @@ public: */ class GameListItemPath : public GameListItem { public: - static const int FullPathRole = Qt::UserRole + 1; - static const int TitleRole = Qt::UserRole + 2; - static const int ProgramIdRole = Qt::UserRole + 3; + static const int TitleRole = SortRole; + static const int FullPathRole = SortRole + 1; + static const int ProgramIdRole = SortRole + 2; GameListItemPath() : GameListItem() {} GameListItemPath(const QString& game_path, const std::vector& smdh_data, u64 program_id) : GameListItem() { + setData(type(), TypeRole); setData(game_path, FullPathRole); setData(qulonglong(program_id), ProgramIdRole); @@ -165,6 +183,10 @@ public: TitleRole); } + int type() const override { + return static_cast(GameListItemType::Game); + } + QVariant data(int role) const override { if (role == Qt::DisplayRole) { std::string filename; @@ -180,9 +202,12 @@ public: class GameListItemCompat : public GameListItem { public: - static const int CompatNumberRole = Qt::UserRole + 1; + static const int CompatNumberRole = SortRole; + GameListItemCompat() = default; explicit GameListItemCompat(const QString compatiblity) { + setData(type(), TypeRole); + auto iterator = status_data.find(compatiblity); if (iterator == status_data.end()) { NGLOG_WARNING(Frontend, "Invalid compatibility number {}", compatiblity.toStdString()); @@ -195,6 +220,10 @@ public: setData(CreateCirclePixmapFromColor(status.color), Qt::DecorationRole); } + int type() const override { + return static_cast(GameListItemType::Game); + } + bool operator<(const QStandardItem& other) const override { return data(CompatNumberRole) < other.data(CompatNumberRole); } @@ -204,6 +233,8 @@ class GameListItemRegion : public GameListItem { public: GameListItemRegion() = default; explicit GameListItemRegion(const std::vector& smdh_data) { + setData(type(), TypeRole); + if (!Loader::IsValidSMDH(smdh_data)) { setText(QObject::tr("Invalid region")); return; @@ -213,6 +244,11 @@ public: memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); setText(GetRegionFromSMDH(smdh)); + setData(GetRegionFromSMDH(smdh), SortRole); + } + + int type() const override { + return static_cast(GameListItemType::Game); } }; @@ -223,10 +259,11 @@ public: */ class GameListItemSize : public GameListItem { public: - static const int SizeRole = Qt::UserRole + 1; + static const int SizeRole = SortRole; GameListItemSize() : GameListItem() {} GameListItemSize(const qulonglong size_bytes) : GameListItem() { + setData(type(), TypeRole); setData(size_bytes, SizeRole); } @@ -242,6 +279,10 @@ public: } } + int type() const override { + return static_cast(GameListItemType::Game); + } + /** * This operator is, in practice, only used by the TreeView sorting systems. * Override it so that it will correctly sort by numerical value instead of by string @@ -252,6 +293,55 @@ public: } }; +class GameListDir : public GameListItem { +public: + static const int GameDirRole = Qt::UserRole + 2; + + explicit GameListDir(UISettings::GameDir& directory, + GameListItemType dir_type = GameListItemType::CustomDir) + : dir_type{dir_type} { + setData(type(), TypeRole); + + UISettings::GameDir* game_dir = &directory; + setData(QVariant::fromValue(game_dir), GameDirRole); + switch (dir_type) { + case GameListItemType::InstalledDir: + setData(QIcon::fromTheme("sd_card").pixmap(48), Qt::DecorationRole); + setData("Installed Titles", Qt::DisplayRole); + break; + case GameListItemType::SystemDir: + setData(QIcon::fromTheme("chip").pixmap(48), Qt::DecorationRole); + setData("System Titles", Qt::DisplayRole); + break; + case GameListItemType::CustomDir: + QString icon_name = QFileInfo::exists(game_dir->path) ? "folder" : "bad_folder"; + setData(QIcon::fromTheme(icon_name).pixmap(48), Qt::DecorationRole); + setData(game_dir->path, Qt::DisplayRole); + break; + }; + }; + + int type() const override { + return static_cast(dir_type); + } + +private: + GameListItemType dir_type; +}; + +class GameListAddDir : public GameListItem { +public: + explicit GameListAddDir() { + setData(type(), TypeRole); + setData(QIcon::fromTheme("plus").pixmap(48), Qt::DecorationRole); + setData("Add New Game Directory", Qt::DisplayRole); + } + + int type() const override { + return static_cast(GameListItemType::AddDir); + } +}; + /** * Asynchronous worker object for populating the game list. * Communicates with other threads through Qt's signal/slot system. @@ -260,11 +350,10 @@ class GameListWorker : public QObject, public QRunnable { Q_OBJECT public: - GameListWorker( - QString dir_path, bool deep_scan, + explicit GameListWorker( + QList& game_dirs, const std::unordered_map>& compatibility_list) - : QObject(), QRunnable(), dir_path(dir_path), deep_scan(deep_scan), - compatibility_list(compatibility_list) {} + : QObject(), QRunnable(), game_dirs(game_dirs), compatibility_list(compatibility_list) {} public slots: /// Starts the processing of directory tree information. @@ -276,22 +365,24 @@ signals: /** * The `EntryReady` signal is emitted once an entry has been prepared and is ready * to be added to the game list. - * @param entry_items a list with `QStandardItem`s that make up the columns of the new entry. + * @param entry_items a list with `QStandardItem`s that make up the columns of the new + * entry. */ - void EntryReady(QList entry_items); + void DirEntryReady(GameListDir* entry_items); + void EntryReady(QList entry_items, GameListDir* parent_dir); /** - * After the worker has traversed the game directory looking for entries, this signal is emmited - * with a list of folders that should be watched for changes as well. + * After the worker has traversed the game directory looking for entries, this signal is + * emitted with a list of folders that should be watched for changes as well. */ void Finished(QStringList watch_list); private: QStringList watch_list; - QString dir_path; - bool deep_scan; const std::unordered_map>& compatibility_list; + QList& game_dirs; std::atomic_bool stop_processing; - void AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion = 0); + void AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion, + GameListDir* parent_dir); }; diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 887f2c191..2bd2ec9a8 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -143,7 +143,7 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { show(); game_list->LoadCompatibilityList(); - game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan); + game_list->PopulateAsync(UISettings::values.game_dirs); // Show one-time "callout" messages to the user ShowCallouts(); @@ -177,6 +177,10 @@ void GMainWindow::InitializeWidgets() { game_list = new GameList(this); ui.horizontalLayout->addWidget(game_list); + game_list_placeholder = new GameListPlaceholder(this); + ui.horizontalLayout->addWidget(game_list_placeholder); + game_list_placeholder->setVisible(false); + multiplayer_state = new MultiplayerState(this, game_list->GetModel(), ui.action_Leave_Room, ui.action_Show_Room); multiplayer_state->setVisible(false); @@ -399,9 +403,14 @@ void GMainWindow::RestoreUIState() { void GMainWindow::ConnectWidgetEvents() { connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile); + connect(game_list, &GameList::OpenDirectory, this, &GMainWindow::OnGameListOpenDirectory); connect(game_list, &GameList::OpenFolderRequested, this, &GMainWindow::OnGameListOpenFolder); connect(game_list, &GameList::NavigateToGamedbEntryRequested, this, &GMainWindow::OnGameListNavigateToGamedbEntry); + connect(game_list, &GameList::AddDirectory, this, &GMainWindow::OnGameListAddDirectory); + connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this, + &GMainWindow::OnGameListAddDirectory); + connect(game_list, &GameList::ShowList, this, &GMainWindow::OnGameListShowList); connect(this, &GMainWindow::EmulationStarting, render_window, &GRenderWindow::OnEmulationStarting); @@ -419,8 +428,6 @@ void GMainWindow::ConnectMenuEvents() { // File connect(ui.action_Load_File, &QAction::triggered, this, &GMainWindow::OnMenuLoadFile); connect(ui.action_Install_CIA, &QAction::triggered, this, &GMainWindow::OnMenuInstallCIA); - connect(ui.action_Select_Game_List_Root, &QAction::triggered, this, - &GMainWindow::OnMenuSelectGameListRoot); connect(ui.action_Exit, &QAction::triggered, this, &QMainWindow::close); // Emulation @@ -672,6 +679,7 @@ void GMainWindow::BootGame(const QString& filename) { registersWidget->OnDebugModeEntered(); if (ui.action_Single_Window_Mode->isChecked()) { game_list->hide(); + game_list_placeholder->hide(); } status_bar_update_timer.start(2000); @@ -713,7 +721,10 @@ void GMainWindow::ShutdownGame() { ui.action_Stop->setEnabled(false); ui.action_Report_Compatibility->setEnabled(false); render_window->hide(); - game_list->show(); + if (game_list->isEmpty()) + game_list_placeholder->show(); + else + game_list->show(); game_list->setFilterFocus(); // Disable status bar updates @@ -828,6 +839,48 @@ void GMainWindow::OnGameListNavigateToGamedbEntry( QDesktopServices::openUrl(QUrl("https://citra-emu.org/game/" + directory)); } +void GMainWindow::OnGameListOpenDirectory(QString directory) { + QString path; + if (directory == "INSTALLED") { + path = + QString::fromStdString(FileUtil::GetUserPath(D_SDMC_IDX).c_str() + + std::string("Nintendo " + "3DS/00000000000000000000000000000000/" + "00000000000000000000000000000000/title/00040000")); + } else if (directory == "SYSTEM") { + path = + QString::fromStdString(FileUtil::GetUserPath(D_NAND_IDX).c_str() + + std::string("00000000000000000000000000000000/title/00040010")); + } else { + path = directory; + } + if (!QFileInfo::exists(path)) { + QMessageBox::critical(this, tr("Error Opening %1").arg(path), tr("Folder does not exist!")); + return; + } + QDesktopServices::openUrl(QUrl::fromLocalFile(path)); +} + +void GMainWindow::OnGameListAddDirectory() { + QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory")); + if (dir_path.isEmpty()) + return; + UISettings::GameDir game_dir{dir_path, false, true}; + if (!UISettings::values.game_dirs.contains(game_dir)) { + UISettings::values.game_dirs.append(game_dir); + game_list->PopulateAsync(UISettings::values.game_dirs); + } else { + NGLOG_WARNING(Frontend, "Selected directory is already in the game list"); + } +} + +void GMainWindow::OnGameListShowList(bool show) { + if (emulation_running && ui.action_Single_Window_Mode->isChecked()) + return; + game_list->setVisible(show); + game_list_placeholder->setVisible(!show); +}; + void GMainWindow::OnMenuLoadFile() { QString extensions; for (const auto& piece : game_list->supported_file_extensions) @@ -845,14 +898,6 @@ void GMainWindow::OnMenuLoadFile() { } } -void GMainWindow::OnMenuSelectGameListRoot() { - QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory")); - if (!dir_path.isEmpty()) { - UISettings::values.gamedir = dir_path; - game_list->PopulateAsync(dir_path, UISettings::values.gamedir_deepscan); - } -} - void GMainWindow::OnMenuInstallCIA() { QStringList filepaths = QFileDialog::getOpenFileNames( this, tr("Load Files"), UISettings::values.roms_path, @@ -1089,6 +1134,7 @@ void GMainWindow::OnConfigure() { if (result == QDialog::Accepted) { configureDialog.applyConfiguration(); UpdateUITheme(); + emit UpdateThemedIcons(); SyncMenuUISettings(); config->Save(); } @@ -1308,7 +1354,6 @@ void GMainWindow::UpdateUITheme() { QIcon::setThemeName(":/icons/default"); } QIcon::setThemeSearchPaths(theme_paths); - emit UpdateThemedIcons(); } void GMainWindow::LoadTranslation() { diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 4ec33cc0d..edb893168 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -20,6 +20,7 @@ class ClickableLabel; class EmuThread; class GameList; enum class GameListOpenTarget; +class GameListPlaceholder; class GImageInfo; class GPUCommandListWidget; class GPUCommandStreamWidget; @@ -148,13 +149,14 @@ private slots: void OnGameListNavigateToGamedbEntry( u64 program_id, std::unordered_map>& compatibility_list); + void OnGameListOpenDirectory(QString path); + void OnGameListAddDirectory(); + void OnGameListShowList(bool show); void OnMenuLoadFile(); void OnMenuInstallCIA(); void OnUpdateProgress(size_t written, size_t total); void OnCIAInstallReport(Service::AM::InstallStatus status, QString filepath); void OnCIAInstallFinished(); - /// Called whenever a user selects the "File->Select Game List Root" menu item - void OnMenuSelectGameListRoot(); void OnMenuRecentFile(); void OnConfigure(); void OnToggleFilterBar(); @@ -184,6 +186,8 @@ private: GRenderWindow* render_window; + GameListPlaceholder* game_list_placeholder; + // Status bar elements QProgressBar* progress_bar = nullptr; QLabel* message_label = nullptr; diff --git a/src/citra_qt/main.ui b/src/citra_qt/main.ui index 86c4e46ed..9b0c512e3 100644 --- a/src/citra_qt/main.ui +++ b/src/citra_qt/main.ui @@ -60,7 +60,6 @@ - diff --git a/src/citra_qt/ui_settings.h b/src/citra_qt/ui_settings.h index 0b084eab6..d8d1d7019 100644 --- a/src/citra_qt/ui_settings.h +++ b/src/citra_qt/ui_settings.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,18 @@ static const std::array, 2> themes = { {std::make_pair(QString("Default"), QString("default")), std::make_pair(QString("Dark"), QString("qdarkstyle"))}}; +struct GameDir { + QString path; + bool deep_scan; + bool expanded; + bool operator==(const GameDir& rhs) const { + return path == rhs.path; + }; + bool operator!=(const GameDir& rhs) const { + return !operator==(rhs); + }; +}; + struct Values { QByteArray geometry; QByteArray state; @@ -45,8 +58,9 @@ struct Values { QString roms_path; QString symbols_path; - QString gamedir; - bool gamedir_deepscan; + QString game_dir_deprecated; + bool game_dir_deprecated_deepscan; + QList game_dirs; QStringList recent_files; QString language; @@ -74,3 +88,5 @@ struct Values { extern Values values; } // namespace UISettings + +Q_DECLARE_METATYPE(UISettings::GameDir*);