2016-06-09 20:11:26 +02:00
/* RetroArch - A frontend for libretro.
2017-01-22 13:40:32 +01:00
* Copyright ( C ) 2011 - 2017 - Daniel De Matteis
2018-10-30 17:11:07 +01:00
* Copyright ( C ) 2018 - Brad Parker
2016-06-09 20:11:26 +02:00
*
* RetroArch is free software : you can redistribute it and / or modify it under the terms
* of the GNU General Public License as published by the Free Software Found -
* ation , either version 3 of the License , or ( at your option ) any later version .
*
* RetroArch is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE . See the GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License along with RetroArch .
* If not , see < http : //www.gnu.org/licenses/>.
*/
2018-04-30 14:33:05 -04:00
# include <QCloseEvent>
2018-08-15 21:40:39 -04:00
# include <QResizeEvent>
2018-04-30 14:33:05 -04:00
# include <QStyle>
# include <QTimer>
# include <QLabel>
# include <QFileSystemModel>
# include <QListWidgetItem>
# include <QTableWidgetItem>
# include <QHash>
# include <QPushButton>
# include <QToolButton>
# include <QMenu>
# include <QDockWidget>
# include <QList>
2018-07-26 00:38:15 -04:00
# include <QInputDialog>
2018-07-26 23:34:29 -04:00
# include <QMimeData>
# include <QProgressDialog>
2018-07-28 10:39:21 -04:00
# include <QDragEnterEvent>
# include <QDropEvent>
2018-05-03 00:49:43 -04:00
# include <QtConcurrentRun>
2018-08-06 20:52:47 -04:00
# include <QtNetwork>
2016-06-09 20:11:26 +02:00
2016-06-10 10:22:49 +02:00
# include "../ui_qt.h"
2018-08-16 22:48:31 -04:00
# include "invader_png.h"
2018-04-30 14:33:05 -04:00
# include "ui_qt_load_core_window.h"
# include "ui_qt_themes.h"
2018-12-12 20:45:19 +01:00
# include "gridview.h"
2018-08-16 22:48:31 -04:00
# include "shaderparamsdialog.h"
2018-08-29 11:34:36 -04:00
# include "coreoptionsdialog.h"
2018-08-16 22:48:31 -04:00
# include "filedropwidget.h"
# include "coreinfodialog.h"
# include "playlistentrydialog.h"
# include "viewoptionsdialog.h"
2016-06-09 20:11:26 +02:00
2019-01-13 21:56:16 -08:00
# ifndef CXX_BUILD
2018-04-30 14:33:05 -04:00
extern " C " {
2019-01-13 21:56:16 -08:00
# endif
2018-04-30 14:33:05 -04:00
# include "../../../version.h"
# include "../../../verbosity.h"
# include "../../../retroarch.h"
# include "../../../msg_hash.h"
# include "../../../core_info.h"
# include "../../../content.h"
# include "../../../paths.h"
# include "../../../configuration.h"
# include "../../../file_path_special.h"
# include "../../../playlist.h"
# include "../../../content.h"
2018-08-16 22:48:31 -04:00
# ifdef HAVE_MENU
2018-04-30 14:33:05 -04:00
# include "../../../menu/menu_driver.h"
2018-08-16 22:48:31 -04:00
# endif
2018-08-06 20:52:47 -04:00
# include "../../../config.def.h"
2019-01-20 03:16:58 +01:00
# include "../../../tasks/task_content.h"
2018-08-16 22:48:31 -04:00
# include "../../../tasks/tasks_internal.h"
2019-02-25 20:10:58 +01:00
# ifdef HAVE_GIT_VERSION
2019-02-15 16:41:52 -05:00
# include "../../../version_git.h"
2019-02-25 20:10:58 +01:00
# endif
2018-04-30 14:33:05 -04:00
# include <string/stdstring.h>
# include <encodings/utf.h>
# include <file/file_path.h>
# include <file/archive_file.h>
2018-08-06 20:52:47 -04:00
# include <streams/file_stream.h>
2018-08-26 10:44:55 -04:00
# ifdef HAVE_OPENSSL
2018-08-26 10:40:33 -04:00
# include <openssl/ssl.h>
# include <openssl/opensslv.h>
2018-08-26 10:44:55 -04:00
# endif
2019-01-13 21:56:16 -08:00
# ifndef CXX_BUILD
2018-04-30 14:33:05 -04:00
}
2019-01-13 21:56:16 -08:00
# endif
2018-04-30 14:33:05 -04:00
2018-08-10 19:10:23 -04:00
# include "../../../AUTHORS.h"
2018-04-30 14:33:05 -04:00
# define TIMER_MSEC 1000 /* periodic timer for gathering statistics */
2018-07-28 23:15:00 -04:00
# define STATUS_MSG_THROTTLE_MSEC 250
2018-04-30 14:33:05 -04:00
# ifndef COLLECTION_SIZE
# define COLLECTION_SIZE 99999
# endif
# define GENERIC_FOLDER_ICON " / xmb / dot-art / png / folder.png"
# define HIRAGANA_START 0x3041U
# define HIRAGANA_END 0x3096U
# define KATAKANA_START 0x30A1U
# define KATAKANA_END 0x30F6U
# define HIRA_KATA_OFFSET (KATAKANA_START - HIRAGANA_START)
2018-08-06 20:52:47 -04:00
# define DOCS_URL "http: //docs.libretro.com/"
2018-04-30 14:33:05 -04:00
static ui_window_qt_t ui_window = { 0 } ;
enum CoreSelection
{
CORE_SELECTION_CURRENT ,
CORE_SELECTION_PLAYLIST_SAVED ,
CORE_SELECTION_PLAYLIST_DEFAULT ,
CORE_SELECTION_ASK ,
CORE_SELECTION_LOAD_CORE
} ;
2018-08-16 22:48:31 -04:00
static const QPixmap getInvader ( )
{
QPixmap pix ;
pix . loadFromData ( invader_png , invader_png_len , " PNG " ) ;
return pix ;
}
2018-04-30 14:33:05 -04:00
# ifdef HAVE_LIBRETRODB
2019-02-08 08:00:32 +01:00
static void scan_finished_handler ( retro_task_t * task ,
void * task_data , void * user_data , const char * err )
2018-04-30 14:33:05 -04:00
{
2018-08-08 12:49:29 -04:00
bool dontAsk = false ;
bool answer = false ;
2019-01-06 17:37:36 -05:00
# ifdef HAVE_MENU
2018-04-30 14:33:05 -04:00
menu_ctx_environment_t menu_environ ;
menu_environ . type = MENU_ENVIRON_RESET_HORIZONTAL_LIST ;
menu_environ . data = NULL ;
2019-01-06 17:37:36 -05:00
# endif
2018-04-30 14:33:05 -04:00
2018-08-16 22:48:31 -04:00
# ifdef HAVE_MENU
2018-04-30 14:33:05 -04:00
menu_driver_ctl ( RARCH_MENU_CTL_ENVIRONMENT , & menu_environ ) ;
2018-08-16 22:48:31 -04:00
# endif
2018-04-30 14:33:05 -04:00
if ( ! ui_window . qtWindow - > settings ( ) - > value ( " scan_finish_confirm " , true ) . toBool ( ) )
return ;
2018-08-08 12:49:29 -04:00
answer = ui_window . qtWindow - > showMessageBox ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_SCAN_FINISHED ) , MainWindow : : MSGBOX_TYPE_QUESTION_OKCANCEL , Qt : : ApplicationModal , true , & dontAsk ) ;
if ( answer & & dontAsk )
2018-04-30 14:33:05 -04:00
ui_window . qtWindow - > settings ( ) - > setValue ( " scan_finish_confirm " , false ) ;
}
# endif
2018-12-12 20:45:19 +01:00
/* https://stackoverflow.com/questions/7246622/how-to-create-a-slider-with-a-non-linear-scale */
2018-08-16 23:14:52 -04:00
static double expScale ( double inputValue , double midValue , double maxValue )
{
double returnValue = 0 ;
double M = maxValue / midValue ;
double C = log ( pow ( M - 1 , 2 ) ) ;
double B = maxValue / ( exp ( C ) - 1 ) ;
double A = - 1 * B ;
returnValue = A + B * exp ( C * inputValue ) ;
return returnValue ;
}
2018-04-30 14:33:05 -04:00
TreeView : : TreeView ( QWidget * parent ) :
QTreeView ( parent )
{
}
void TreeView : : columnCountChanged ( int oldCount , int newCount )
{
QTreeView : : columnCountChanged ( oldCount , newCount ) ;
}
void TreeView : : selectionChanged ( const QItemSelection & selected , const QItemSelection & deselected )
{
QModelIndexList list = selected . indexes ( ) ;
QTreeView : : selectionChanged ( selected , deselected ) ;
emit itemsSelected ( list ) ;
}
2018-12-12 20:45:19 +01:00
TableView : : TableView ( QWidget * parent ) :
QTableView ( parent )
2018-04-30 14:33:05 -04:00
{
}
2018-12-12 20:45:19 +01:00
bool TableView : : isEditorOpen ( )
2018-09-17 23:12:08 -04:00
{
return ( state ( ) = = QAbstractItemView : : EditingState ) ;
}
2018-09-18 14:09:25 -04:00
ListWidget : : ListWidget ( QWidget * parent ) :
QListWidget ( parent )
{
}
bool ListWidget : : isEditorOpen ( )
{
return ( state ( ) = = QAbstractItemView : : EditingState ) ;
}
void ListWidget : : keyPressEvent ( QKeyEvent * event )
{
if ( event - > key ( ) = = Qt : : Key_Return | | event - > key ( ) = = Qt : : Key_Enter )
emit enterPressed ( ) ;
else if ( event - > key ( ) = = Qt : : Key_Delete )
emit deletePressed ( ) ;
QListWidget : : keyPressEvent ( event ) ;
}
2018-04-30 14:33:05 -04:00
CoreInfoLabel : : CoreInfoLabel ( QString text , QWidget * parent ) :
QLabel ( text , parent )
{
setTextInteractionFlags ( Qt : : TextSelectableByMouse | Qt : : TextSelectableByKeyboard ) ;
}
CoreInfoWidget : : CoreInfoWidget ( CoreInfoLabel * label , QWidget * parent ) :
QWidget ( parent )
, m_label ( label )
, m_scrollArea ( new QScrollArea ( this ) )
{
m_scrollArea - > setWidgetResizable ( true ) ;
m_scrollArea - > setWidget ( m_label ) ;
}
QSize CoreInfoWidget : : sizeHint ( ) const
{
return QSize ( 256 , 256 ) ;
}
void CoreInfoWidget : : resizeEvent ( QResizeEvent * event )
{
QWidget : : resizeEvent ( event ) ;
m_scrollArea - > resize ( event - > size ( ) ) ;
}
LogTextEdit : : LogTextEdit ( QWidget * parent ) :
QPlainTextEdit ( parent )
{
}
void LogTextEdit : : appendMessage ( const QString & text )
{
if ( text . isEmpty ( ) )
return ;
appendPlainText ( text ) ;
verticalScrollBar ( ) - > setValue ( verticalScrollBar ( ) - > maximum ( ) ) ;
}
2019-01-07 20:56:23 +01:00
/* only accept indexes from current path. https://www.qtcentre.org/threads/50700-QFileSystemModel-and-QSortFilterProxyModel-don-t-work-well-together */
bool FileSystemProxyModel : : filterAcceptsRow ( int sourceRow , const QModelIndex & sourceParent ) const
{
QModelIndex rootIndex ;
QFileSystemModel * sm = qobject_cast < QFileSystemModel * > ( sourceModel ( ) ) ;
rootIndex = sm - > index ( sm - > rootPath ( ) ) ;
if ( sourceParent = = rootIndex )
{
return QSortFilterProxyModel : : filterAcceptsRow ( sourceRow , sourceParent ) ;
}
return true ;
}
void FileSystemProxyModel : : sort ( int column , Qt : : SortOrder order )
{
/* sort the source (QFileSystemModel to keep directories before files) */
sourceModel ( ) - > sort ( column , order ) ;
}
2018-04-30 14:33:05 -04:00
MainWindow : : MainWindow ( QWidget * parent ) :
QMainWindow ( parent )
, m_loadCoreWindow ( new LoadCoreWindow ( this ) )
, m_timer ( new QTimer ( this ) )
, m_currentCore ( )
, m_currentCoreVersion ( )
, m_statusLabel ( new QLabel ( this ) )
, m_dirTree ( new TreeView ( this ) )
, m_dirModel ( new QFileSystemModel ( m_dirTree ) )
2019-01-07 20:56:23 +01:00
, m_fileModel ( new QFileSystemModel ( this ) )
2018-09-18 14:09:25 -04:00
, m_listWidget ( new ListWidget ( this ) )
2019-01-07 20:56:23 +01:00
, m_centralWidget ( new QStackedWidget ( this ) )
2018-12-12 20:45:19 +01:00
, m_tableView ( new TableView ( this ) )
2019-01-07 20:56:23 +01:00
, m_fileTableView ( new QTableView ( this ) )
, m_playlistViews ( new FileDropWidget ( this ) )
2018-04-30 14:33:05 -04:00
, m_searchWidget ( new QWidget ( this ) )
, m_searchLineEdit ( new QLineEdit ( this ) )
, m_searchDock ( new QDockWidget ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_MENU_EDIT_SEARCH ) , this ) )
, m_playlistFiles ( )
, m_launchWithComboBox ( new QComboBox ( this ) )
, m_startCorePushButton ( new QToolButton ( this ) )
, m_coreInfoPushButton ( new QToolButton ( this ) )
, m_runPushButton ( new QToolButton ( this ) )
, m_stopPushButton ( new QToolButton ( this ) )
, m_browserAndPlaylistTabWidget ( new QTabWidget ( this ) )
, m_pendingRun ( false )
, m_thumbnailPixmap ( NULL )
, m_thumbnailPixmap2 ( NULL )
, m_thumbnailPixmap3 ( NULL )
, m_settings ( NULL )
, m_viewOptionsDialog ( NULL )
, m_coreInfoDialog ( new CoreInfoDialog ( this , NULL ) )
, m_defaultStyle ( NULL )
, m_defaultPalette ( )
, m_currentTheme ( THEME_SYSTEM_DEFAULT )
, m_coreInfoDock ( new QDockWidget ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_CORE_INFO ) , this ) )
, m_coreInfoLabel ( new CoreInfoLabel ( QString ( ) , this ) )
, m_coreInfoWidget ( new CoreInfoWidget ( m_coreInfoLabel , this ) )
, m_logDock ( new QDockWidget ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_LOG ) , this ) )
2019-01-14 20:06:07 +01:00
, m_logWidget ( new QFrame ( this ) )
2018-04-30 14:33:05 -04:00
, m_logTextEdit ( new LogTextEdit ( m_logWidget ) )
, m_historyPlaylistsItem ( NULL )
, m_folderIcon ( )
, m_customThemeString ( )
2018-12-12 20:45:19 +01:00
, m_gridView ( new GridView ( this ) )
2019-01-13 23:34:47 +01:00
, m_playlistViewsAndFooter ( new QWidget ( this ) )
2018-05-03 02:47:40 -04:00
, m_zoomSlider ( NULL )
, m_lastZoomSliderValue ( 0 )
2018-05-07 02:36:00 -04:00
, m_viewType ( VIEW_TYPE_LIST )
2018-12-23 02:59:42 +01:00
, m_thumbnailType ( THUMBNAIL_TYPE_BOXART )
2018-07-22 22:05:57 -04:00
, m_gridProgressBar ( NULL )
, m_gridProgressWidget ( NULL )
2018-07-23 11:17:58 -04:00
, m_currentGridHash ( )
2018-07-25 00:29:48 -04:00
, m_currentGridWidget ( NULL )
2018-07-25 15:24:26 -04:00
, m_allPlaylistsListMaxCount ( 0 )
, m_allPlaylistsGridMaxCount ( 0 )
2018-07-27 23:45:48 -04:00
, m_playlistEntryDialog ( NULL )
2018-07-28 23:15:00 -04:00
, m_statusMessageElapsedTimer ( )
2018-08-18 00:33:52 -04:00
, m_shaderParamsDialog ( new ShaderParamsDialog ( ) )
2018-08-29 11:34:36 -04:00
, m_coreOptionsDialog ( new CoreOptionsDialog ( ) )
2018-08-06 20:52:47 -04:00
, m_networkManager ( new QNetworkAccessManager ( this ) )
, m_updateProgressDialog ( new QProgressDialog ( ) )
, m_updateFile ( )
, m_updateReply ( )
2018-08-25 01:00:18 -04:00
, m_thumbnailDownloadProgressDialog ( new QProgressDialog ( ) )
2018-08-26 23:24:43 -04:00
, m_thumbnailDownloadFile ( )
2018-08-25 01:00:18 -04:00
, m_thumbnailDownloadReply ( )
, m_pendingThumbnailDownloadTypes ( )
2018-08-26 23:24:43 -04:00
, m_thumbnailPackDownloadProgressDialog ( new QProgressDialog ( ) )
, m_thumbnailPackDownloadFile ( )
, m_thumbnailPackDownloadReply ( )
2018-08-27 23:29:44 -04:00
, m_playlistThumbnailDownloadProgressDialog ( new QProgressDialog ( ) )
, m_playlistThumbnailDownloadFile ( )
, m_playlistThumbnailDownloadReply ( )
, m_pendingPlaylistThumbnails ( )
, m_downloadedThumbnails ( 0 )
, m_failedThumbnails ( 0 )
2018-08-28 09:01:25 -04:00
, m_playlistThumbnailDownloadWasCanceled ( false )
2018-09-01 21:24:59 -04:00
, m_pendingDirScrollPath ( )
2018-12-19 01:11:52 +01:00
, m_thumbnailTimer ( new QTimer ( this ) )
2018-12-23 00:45:00 +01:00
, m_gridItem ( this )
2019-01-07 20:56:23 +01:00
, m_currentBrowser ( BROWSER_TYPE_PLAYLISTS )
, m_searchRegExp ( )
, m_zoomWidget ( new QWidget ( this ) )
, m_itemsCountLiteral ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_ITEMS_COUNT ) )
, m_itemsCountLabel ( new QLabel ( this ) )
2018-04-30 14:33:05 -04:00
{
settings_t * settings = config_get_ptr ( ) ;
QDir playlistDir ( settings - > paths . directory_playlist ) ;
QString configDir = QFileInfo ( path_get ( RARCH_PATH_CONFIG ) ) . dir ( ) . absolutePath ( ) ;
QToolButton * searchResetButton = NULL ;
2018-05-03 02:47:40 -04:00
QHBoxLayout * zoomLayout = new QHBoxLayout ( ) ;
2019-01-07 20:56:23 +01:00
QLabel * zoomLabel = new QLabel ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_ZOOM ) , m_zoomWidget ) ;
2019-04-01 21:31:46 +02:00
QPushButton * thumbnailTypePushButton = new QPushButton ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THUMBNAIL_TYPE ) , m_zoomWidget ) ;
QMenu * thumbnailTypeMenu = new QMenu ( thumbnailTypePushButton ) ;
QAction * thumbnailTypeBoxartAction = NULL ;
QAction * thumbnailTypeScreenshotAction = NULL ;
QAction * thumbnailTypeTitleAction = NULL ;
2019-01-07 20:56:23 +01:00
QPushButton * viewTypePushButton = new QPushButton ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_VIEW ) , m_zoomWidget ) ;
2018-05-07 02:36:00 -04:00
QMenu * viewTypeMenu = new QMenu ( viewTypePushButton ) ;
QAction * viewTypeIconsAction = NULL ;
QAction * viewTypeListAction = NULL ;
2018-07-22 22:05:57 -04:00
QHBoxLayout * gridProgressLayout = new QHBoxLayout ( ) ;
QLabel * gridProgressLabel = NULL ;
QHBoxLayout * gridFooterLayout = NULL ;
2018-04-30 14:33:05 -04:00
2018-05-07 14:29:54 -04:00
qRegisterMetaType < QPointer < ThumbnailWidget > > ( " ThumbnailWidget " ) ;
2018-08-26 23:24:43 -04:00
qRegisterMetaType < retro_task_callback_t > ( " retro_task_callback_t " ) ;
2018-05-07 14:29:54 -04:00
2018-08-26 23:24:43 -04:00
/* Cancel all progress dialogs immediately since they show as soon as they're constructed. */
2018-08-06 20:52:47 -04:00
m_updateProgressDialog - > cancel ( ) ;
2018-08-25 01:00:18 -04:00
m_thumbnailDownloadProgressDialog - > cancel ( ) ;
2018-08-26 23:24:43 -04:00
m_thumbnailPackDownloadProgressDialog - > cancel ( ) ;
2018-08-27 23:29:44 -04:00
m_playlistThumbnailDownloadProgressDialog - > cancel ( ) ;
2018-08-06 20:52:47 -04:00
2018-07-22 22:05:57 -04:00
m_gridProgressWidget = new QWidget ( ) ;
gridProgressLabel = new QLabel ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_PROGRESS ) , m_gridProgressWidget ) ;
2019-04-01 21:31:46 +02:00
thumbnailTypePushButton - > setObjectName ( " thumbnailTypePushButton " ) ;
thumbnailTypePushButton - > setFlat ( true ) ;
thumbnailTypeBoxartAction = thumbnailTypeMenu - > addAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_THUMBNAIL_BOXART ) ) ;
thumbnailTypeScreenshotAction = thumbnailTypeMenu - > addAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_THUMBNAIL_SCREENSHOT ) ) ;
thumbnailTypeTitleAction = thumbnailTypeMenu - > addAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_THUMBNAIL_TITLE_SCREEN ) ) ;
thumbnailTypePushButton - > setMenu ( thumbnailTypeMenu ) ;
2018-05-07 02:36:00 -04:00
viewTypePushButton - > setObjectName ( " viewTypePushButton " ) ;
viewTypePushButton - > setFlat ( true ) ;
viewTypeIconsAction = viewTypeMenu - > addAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS ) ) ;
viewTypeListAction = viewTypeMenu - > addAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_LIST ) ) ;
viewTypePushButton - > setMenu ( viewTypeMenu ) ;
2018-07-22 22:05:57 -04:00
gridProgressLabel - > setObjectName ( " gridProgressLabel " ) ;
m_gridProgressBar = new QProgressBar ( m_gridProgressWidget ) ;
m_gridProgressBar - > setSizePolicy ( QSizePolicy ( QSizePolicy : : Minimum , QSizePolicy : : Preferred ) ) ;
2018-05-03 23:58:15 -04:00
zoomLabel - > setObjectName ( " zoomLabel " ) ;
2019-01-07 20:56:23 +01:00
m_zoomSlider = new QSlider ( Qt : : Horizontal , m_zoomWidget ) ;
2018-05-03 02:47:40 -04:00
2018-05-03 23:58:15 -04:00
m_zoomSlider - > setMinimum ( 0 ) ;
m_zoomSlider - > setMaximum ( 100 ) ;
2018-05-03 02:47:40 -04:00
m_zoomSlider - > setValue ( 50 ) ;
2018-07-22 22:05:57 -04:00
m_zoomSlider - > setSizePolicy ( QSizePolicy ( QSizePolicy : : Minimum , QSizePolicy : : Preferred ) ) ;
2018-05-03 02:47:40 -04:00
m_lastZoomSliderValue = m_zoomSlider - > value ( ) ;
2019-01-13 23:34:47 +01:00
m_playlistViewsAndFooter - > setLayout ( new QVBoxLayout ( ) ) ;
2018-05-02 23:04:10 -04:00
2018-12-12 20:45:19 +01:00
m_gridView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
m_gridView - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ;
2018-05-02 23:04:10 -04:00
2019-01-13 23:34:47 +01:00
m_playlistViews - > addWidget ( m_gridView ) ;
m_playlistViews - > addWidget ( m_tableView ) ;
m_centralWidget - > setObjectName ( " centralWidget " ) ;
m_playlistViewsAndFooter - > layout ( ) - > addWidget ( m_playlistViews ) ;
m_playlistViewsAndFooter - > layout ( ) - > setAlignment ( Qt : : AlignCenter ) ;
m_playlistViewsAndFooter - > layout ( ) - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2018-05-02 23:04:10 -04:00
2018-07-22 22:05:57 -04:00
m_gridProgressWidget - > setLayout ( gridProgressLayout ) ;
gridProgressLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
gridProgressLayout - > addSpacerItem ( new QSpacerItem ( 0 , 0 , QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ) ;
gridProgressLayout - > addWidget ( gridProgressLabel ) ;
gridProgressLayout - > addWidget ( m_gridProgressBar ) ;
2019-01-13 23:34:47 +01:00
m_playlistViewsAndFooter - > layout ( ) - > addWidget ( m_gridProgressWidget ) ;
2018-05-03 02:47:40 -04:00
2019-01-07 20:56:23 +01:00
m_zoomWidget - > setLayout ( zoomLayout ) ;
2018-05-04 12:05:53 -04:00
zoomLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2018-05-03 23:58:15 -04:00
zoomLayout - > addWidget ( zoomLabel ) ;
2018-05-03 02:47:40 -04:00
zoomLayout - > addWidget ( m_zoomSlider ) ;
2019-01-10 01:01:01 +01:00
m_itemsCountLabel - > setObjectName ( " itemsCountLabel " ) ;
2018-05-03 02:47:40 -04:00
2018-07-22 22:05:57 -04:00
gridFooterLayout = new QHBoxLayout ( ) ;
2019-01-07 20:56:23 +01:00
gridFooterLayout - > addWidget ( m_itemsCountLabel ) ;
2018-07-22 22:05:57 -04:00
gridFooterLayout - > addSpacerItem ( new QSpacerItem ( 0 , 0 , QSizePolicy : : Expanding , QSizePolicy : : Preferred ) ) ;
gridFooterLayout - > addWidget ( m_gridProgressWidget ) ;
2019-01-07 20:56:23 +01:00
gridFooterLayout - > addWidget ( m_zoomWidget ) ;
2019-04-01 21:31:46 +02:00
gridFooterLayout - > addWidget ( thumbnailTypePushButton ) ;
2019-01-07 20:56:23 +01:00
gridFooterLayout - > addWidget ( viewTypePushButton ) ;
2018-07-22 22:05:57 -04:00
2019-01-13 23:34:47 +01:00
static_cast < QVBoxLayout * > ( m_playlistViewsAndFooter - > layout ( ) ) - > addLayout ( gridFooterLayout ) ;
2018-07-22 22:05:57 -04:00
m_gridProgressWidget - > hide ( ) ;
2018-05-03 02:47:40 -04:00
2018-12-12 20:45:19 +01:00
m_playlistModel = new PlaylistModel ( this ) ;
m_proxyModel = new QSortFilterProxyModel ( this ) ;
m_proxyModel - > setSourceModel ( m_playlistModel ) ;
m_proxyModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
2019-01-07 20:56:23 +01:00
m_proxyFileModel = new FileSystemProxyModel ( ) ;
m_proxyFileModel - > setSourceModel ( m_fileModel ) ;
m_proxyFileModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
2018-12-12 20:45:19 +01:00
m_tableView - > setAlternatingRowColors ( true ) ;
m_tableView - > setModel ( m_proxyModel ) ;
2018-12-14 23:19:53 +01:00
m_tableView - > setSortingEnabled ( true ) ;
m_tableView - > verticalHeader ( ) - > setVisible ( false ) ;
2019-01-07 20:56:23 +01:00
m_tableView - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ;
m_tableView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
m_tableView - > setEditTriggers ( QAbstractItemView : : SelectedClicked | QAbstractItemView : : EditKeyPressed ) ;
m_tableView - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAsNeeded ) ;
m_tableView - > setHorizontalScrollMode ( QAbstractItemView : : ScrollPerPixel ) ;
m_tableView - > horizontalHeader ( ) - > setStretchLastSection ( true ) ;
2019-01-13 20:57:19 +01:00
m_tableView - > setWordWrap ( false ) ;
2019-01-07 20:56:23 +01:00
m_fileTableView - > setModel ( m_fileModel ) ;
m_fileTableView - > sortByColumn ( 0 , Qt : : AscendingOrder ) ;
m_fileTableView - > setSortingEnabled ( true ) ;
m_fileTableView - > setAlternatingRowColors ( true ) ;
m_fileTableView - > verticalHeader ( ) - > setVisible ( false ) ;
m_fileTableView - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
m_fileTableView - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ;
m_fileTableView - > horizontalHeader ( ) - > setStretchLastSection ( true ) ;
m_fileTableView - > setHorizontalScrollMode ( QAbstractItemView : : ScrollPerPixel ) ;
2019-01-13 20:57:19 +01:00
m_fileTableView - > setWordWrap ( false ) ;
2018-12-12 20:45:19 +01:00
2018-12-23 00:45:00 +01:00
m_gridView - > setItemDelegate ( new ThumbnailDelegate ( m_gridItem , this ) ) ;
2018-12-12 20:45:19 +01:00
m_gridView - > setModel ( m_proxyModel ) ;
2018-04-30 14:33:05 -04:00
2019-01-07 20:56:23 +01:00
m_gridView - > setSelectionModel ( m_tableView - > selectionModel ( ) ) ;
2018-04-30 14:33:05 -04:00
m_logWidget - > setObjectName ( " logWidget " ) ;
m_folderIcon = QIcon ( QString ( settings - > paths . directory_assets ) + GENERIC_FOLDER_ICON ) ;
m_imageFormats = QVector < QByteArray > : : fromList ( QImageReader : : supportedImageFormats ( ) ) ;
m_defaultStyle = QApplication : : style ( ) ;
m_defaultPalette = QApplication : : palette ( ) ;
/* ViewOptionsDialog needs m_settings set before it's constructed */
m_settings = new QSettings ( configDir + " /retroarch_qt.cfg " , QSettings : : IniFormat , this ) ;
m_viewOptionsDialog = new ViewOptionsDialog ( this , 0 ) ;
2018-07-27 23:45:48 -04:00
m_playlistEntryDialog = new PlaylistEntryDialog ( this , 0 ) ;
2018-04-30 14:33:05 -04:00
/* default NULL parameter for parent wasn't added until 5.7 */
m_startCorePushButton - > setDefaultAction ( new QAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_START_CORE ) , m_startCorePushButton ) ) ;
m_startCorePushButton - > setFixedSize ( m_startCorePushButton - > sizeHint ( ) ) ;
m_runPushButton - > setDefaultAction ( new QAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_RUN ) , m_runPushButton ) ) ;
m_runPushButton - > setFixedSize ( m_runPushButton - > sizeHint ( ) ) ;
m_stopPushButton - > setDefaultAction ( new QAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_STOP ) , m_stopPushButton ) ) ;
m_stopPushButton - > setFixedSize ( m_stopPushButton - > sizeHint ( ) ) ;
m_coreInfoPushButton - > setDefaultAction ( new QAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_INFO ) , m_coreInfoPushButton ) ) ;
m_coreInfoPushButton - > setFixedSize ( m_coreInfoPushButton - > sizeHint ( ) ) ;
searchResetButton = new QToolButton ( m_searchWidget ) ;
2018-05-07 15:37:54 +02:00
searchResetButton - > setDefaultAction ( new QAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_MENU_SEARCH_CLEAR ) , searchResetButton ) ) ;
2018-04-30 14:33:05 -04:00
searchResetButton - > setFixedSize ( searchResetButton - > sizeHint ( ) ) ;
connect ( searchResetButton , SIGNAL ( clicked ( ) ) , this , SLOT ( onSearchResetClicked ( ) ) ) ;
m_dirModel - > setFilter ( QDir : : NoDotAndDotDot |
QDir : : AllDirs |
QDir : : Drives |
( m_settings - > value ( " show_hidden_files " , true ) . toBool ( ) ? ( QDir : : Hidden | QDir : : System ) : static_cast < QDir : : Filter > ( 0 ) ) ) ;
2019-01-07 20:56:23 +01:00
m_fileModel - > setFilter ( QDir : : NoDot |
QDir : : AllEntries |
( m_settings - > value ( " show_hidden_files " , true ) . toBool ( ) ? ( QDir : : Hidden | QDir : : System ) : static_cast < QDir : : Filter > ( 0 ) ) ) ;
2018-04-30 14:33:05 -04:00
# if defined(Q_OS_WIN)
m_dirModel - > setRootPath ( " " ) ;
2019-01-07 20:56:23 +01:00
m_fileModel - > setRootPath ( " " ) ;
2018-04-30 14:33:05 -04:00
# else
m_dirModel - > setRootPath ( " / " ) ;
2019-01-07 20:56:23 +01:00
m_fileModel - > setRootPath ( " / " ) ;
2018-04-30 14:33:05 -04:00
# endif
m_dirTree - > setModel ( m_dirModel ) ;
m_dirTree - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
2019-01-07 20:56:23 +01:00
m_dirTree - > header ( ) - > setVisible ( false ) ;
m_fileTableView - > setModel ( m_proxyFileModel ) ;
2018-04-30 14:33:05 -04:00
if ( m_dirModel - > columnCount ( ) > 3 )
{
/* size */
m_dirTree - > hideColumn ( 1 ) ;
/* type */
m_dirTree - > hideColumn ( 2 ) ;
/* date modified */
m_dirTree - > hideColumn ( 3 ) ;
}
reloadPlaylists ( ) ;
m_searchWidget - > setLayout ( new QHBoxLayout ( ) ) ;
m_searchWidget - > layout ( ) - > addWidget ( m_searchLineEdit ) ;
m_searchWidget - > layout ( ) - > addWidget ( searchResetButton ) ;
m_searchDock - > setObjectName ( " searchDock " ) ;
m_searchDock - > setProperty ( " default_area " , Qt : : LeftDockWidgetArea ) ;
m_searchDock - > setProperty ( " menu_text " , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_SEARCH ) ) ;
m_searchDock - > setWidget ( m_searchWidget ) ;
2019-01-11 01:31:27 +01:00
m_searchDock - > setFixedHeight ( m_searchDock - > minimumSizeHint ( ) . height ( ) ) ;
2018-04-30 14:33:05 -04:00
addDockWidget ( static_cast < Qt : : DockWidgetArea > ( m_searchDock - > property ( " default_area " ) . toInt ( ) ) , m_searchDock ) ;
m_coreInfoLabel - > setAlignment ( Qt : : AlignLeft | Qt : : AlignTop ) ;
m_coreInfoLabel - > setTextFormat ( Qt : : RichText ) ;
2018-08-03 21:14:27 -04:00
m_coreInfoLabel - > setTextInteractionFlags ( Qt : : TextBrowserInteraction ) ;
m_coreInfoLabel - > setOpenExternalLinks ( true ) ;
2018-04-30 14:33:05 -04:00
m_coreInfoDock - > setObjectName ( " coreInfoDock " ) ;
m_coreInfoDock - > setProperty ( " default_area " , Qt : : RightDockWidgetArea ) ;
m_coreInfoDock - > setProperty ( " menu_text " , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_CORE_INFO ) ) ;
m_coreInfoDock - > setWidget ( m_coreInfoWidget ) ;
addDockWidget ( static_cast < Qt : : DockWidgetArea > ( m_coreInfoDock - > property ( " default_area " ) . toInt ( ) ) , m_coreInfoDock ) ;
m_logWidget - > setLayout ( new QVBoxLayout ( ) ) ;
m_logWidget - > layout ( ) - > addWidget ( m_logTextEdit ) ;
2019-01-14 20:06:07 +01:00
m_logWidget - > layout ( ) - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2018-04-30 14:33:05 -04:00
m_logDock - > setObjectName ( " logDock " ) ;
m_logDock - > setProperty ( " default_area " , Qt : : BottomDockWidgetArea ) ;
m_logDock - > setProperty ( " menu_text " , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_LOG ) ) ;
m_logDock - > setWidget ( m_logWidget ) ;
addDockWidget ( static_cast < Qt : : DockWidgetArea > ( m_logDock - > property ( " default_area " ) . toInt ( ) ) , m_logDock ) ;
/* Hide the log by default. If user has saved their dock positions with the log visible,
* then this hide ( ) call will be reversed later by restoreState ( ) .
* FIXME : If user unchecks " save dock positions " , the log will not be unhidden even if
* it was previously saved in the config .
*/
m_logDock - > hide ( ) ;
m_dirTree - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
m_listWidget - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( m_searchLineEdit , SIGNAL ( returnPressed ( ) ) , this , SLOT ( onSearchEnterPressed ( ) ) ) ;
connect ( m_searchLineEdit , SIGNAL ( textEdited ( const QString & ) ) , this , SLOT ( onSearchLineEditEdited ( const QString & ) ) ) ;
connect ( m_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( onTimeout ( ) ) ) ;
connect ( m_loadCoreWindow , SIGNAL ( coreLoaded ( ) ) , this , SLOT ( onCoreLoaded ( ) ) ) ;
connect ( m_loadCoreWindow , SIGNAL ( windowClosed ( ) ) , this , SLOT ( onCoreLoadWindowClosed ( ) ) ) ;
connect ( m_listWidget , SIGNAL ( currentItemChanged ( QListWidgetItem * , QListWidgetItem * ) ) , this , SLOT ( onCurrentListItemChanged ( QListWidgetItem * , QListWidgetItem * ) ) ) ;
connect ( m_startCorePushButton , SIGNAL ( clicked ( ) ) , this , SLOT ( onStartCoreClicked ( ) ) ) ;
connect ( m_coreInfoPushButton , SIGNAL ( clicked ( ) ) , m_coreInfoDialog , SLOT ( showCoreInfo ( ) ) ) ;
connect ( m_runPushButton , SIGNAL ( clicked ( ) ) , this , SLOT ( onRunClicked ( ) ) ) ;
connect ( m_stopPushButton , SIGNAL ( clicked ( ) ) , this , SLOT ( onStopClicked ( ) ) ) ;
connect ( m_dirTree , SIGNAL ( itemsSelected ( QModelIndexList ) ) , this , SLOT ( onTreeViewItemsSelected ( QModelIndexList ) ) ) ;
connect ( m_dirTree , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( onFileBrowserTreeContextMenuRequested ( const QPoint & ) ) ) ;
connect ( m_listWidget , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( onPlaylistWidgetContextMenuRequested ( const QPoint & ) ) ) ;
connect ( m_launchWithComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( onLaunchWithComboBoxIndexChanged ( int ) ) ) ;
2018-05-03 02:47:40 -04:00
connect ( m_zoomSlider , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( onZoomValueChanged ( int ) ) ) ;
2019-04-01 21:31:46 +02:00
connect ( thumbnailTypeBoxartAction , SIGNAL ( triggered ( ) ) , this , SLOT ( onBoxartThumbnailClicked ( ) ) ) ;
connect ( thumbnailTypeScreenshotAction , SIGNAL ( triggered ( ) ) , this , SLOT ( onScreenshotThumbnailClicked ( ) ) ) ;
connect ( thumbnailTypeTitleAction , SIGNAL ( triggered ( ) ) , this , SLOT ( onTitleThumbnailClicked ( ) ) ) ;
2018-05-07 02:36:00 -04:00
connect ( viewTypeIconsAction , SIGNAL ( triggered ( ) ) , this , SLOT ( onIconViewClicked ( ) ) ) ;
connect ( viewTypeListAction , SIGNAL ( triggered ( ) ) , this , SLOT ( onListViewClicked ( ) ) ) ;
2018-09-01 21:24:59 -04:00
connect ( m_dirModel , SIGNAL ( directoryLoaded ( const QString & ) ) , this , SLOT ( onFileSystemDirLoaded ( const QString & ) ) ) ;
2019-01-07 20:56:23 +01:00
connect ( m_fileModel , SIGNAL ( directoryLoaded ( const QString & ) ) , this , SLOT ( onFileBrowserTableDirLoaded ( const QString & ) ) ) ;
m_dirTree - > setCurrentIndex ( m_dirModel - > index ( settings - > paths . directory_menu_content ) ) ;
m_dirTree - > scrollTo ( m_dirTree - > currentIndex ( ) , QAbstractItemView : : PositionAtTop ) ;
m_dirTree - > expand ( m_dirTree - > currentIndex ( ) ) ;
2018-09-01 21:24:59 -04:00
/* must use queued connection */
connect ( this , SIGNAL ( scrollToDownloads ( QString ) ) , this , SLOT ( onDownloadScroll ( QString ) ) , Qt : : QueuedConnection ) ;
connect ( this , SIGNAL ( scrollToDownloadsAgain ( QString ) ) , this , SLOT ( onDownloadScrollAgain ( QString ) ) , Qt : : QueuedConnection ) ;
2018-04-30 14:33:05 -04:00
2018-08-28 09:01:25 -04:00
connect ( m_playlistThumbnailDownloadProgressDialog , SIGNAL ( canceled ( ) ) , m_playlistThumbnailDownloadProgressDialog , SLOT ( cancel ( ) ) ) ;
connect ( m_playlistThumbnailDownloadProgressDialog , SIGNAL ( canceled ( ) ) , this , SLOT ( onPlaylistThumbnailDownloadCanceled ( ) ) ) ;
connect ( m_thumbnailDownloadProgressDialog , SIGNAL ( canceled ( ) ) , m_thumbnailDownloadProgressDialog , SLOT ( cancel ( ) ) ) ;
connect ( m_thumbnailDownloadProgressDialog , SIGNAL ( canceled ( ) ) , this , SLOT ( onThumbnailDownloadCanceled ( ) ) ) ;
connect ( m_thumbnailPackDownloadProgressDialog , SIGNAL ( canceled ( ) ) , m_thumbnailPackDownloadProgressDialog , SLOT ( cancel ( ) ) ) ;
connect ( m_thumbnailPackDownloadProgressDialog , SIGNAL ( canceled ( ) ) , this , SLOT ( onThumbnailPackDownloadCanceled ( ) ) ) ;
2018-08-25 01:00:18 -04:00
connect ( this , SIGNAL ( itemChanged ( ) ) , this , SLOT ( onItemChanged ( ) ) ) ;
connect ( this , SIGNAL ( gotThumbnailDownload ( QString , QString ) ) , this , SLOT ( onDownloadThumbnail ( QString , QString ) ) ) ;
2018-12-12 20:45:19 +01:00
m_thumbnailTimer - > setSingleShot ( true ) ;
connect ( m_thumbnailTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateVisibleItems ( ) ) ) ;
connect ( this , SIGNAL ( updateThumbnails ( ) ) , this , SLOT ( updateVisibleItems ( ) ) ) ;
2018-12-23 00:45:00 +01:00
/* TODO: Handle scroll and resize differently. */
2018-12-12 20:45:19 +01:00
connect ( m_gridView , SIGNAL ( visibleItemsChangedMaybe ( ) ) , this , SLOT ( startTimer ( ) ) ) ;
2019-01-07 20:56:23 +01:00
connect ( m_tableView - > selectionModel ( ) , SIGNAL ( currentChanged ( const QModelIndex & , const QModelIndex & ) ) , this , SLOT ( onCurrentItemChanged ( const QModelIndex & ) ) ) ;
connect ( m_fileTableView - > selectionModel ( ) , SIGNAL ( currentChanged ( const QModelIndex & , const QModelIndex & ) ) , this , SLOT ( onCurrentFileChanged ( const QModelIndex & ) ) ) ;
2018-12-12 20:45:19 +01:00
connect ( m_gridView , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( onContentItemDoubleClicked ( const QModelIndex & ) ) ) ;
connect ( m_tableView , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( onContentItemDoubleClicked ( const QModelIndex & ) ) ) ;
2019-01-07 20:56:23 +01:00
connect ( m_fileTableView , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( onFileDoubleClicked ( const QModelIndex & ) ) ) ;
2018-12-12 20:45:19 +01:00
connect ( m_playlistModel , SIGNAL ( dataChanged ( const QModelIndex & , const QModelIndex & , const QVector < int > & ) ) , this , SLOT ( onCurrentTableItemDataChanged ( const QModelIndex & , const QModelIndex & , const QVector < int > & ) ) ) ;
2018-04-30 14:33:05 -04:00
/* make sure these use an auto connection so it will be queued if called from a different thread (some facilities in RA log messages from other threads) */
connect ( this , SIGNAL ( gotLogMessage ( const QString & ) ) , this , SLOT ( onGotLogMessage ( const QString & ) ) , Qt : : AutoConnection ) ;
connect ( this , SIGNAL ( gotStatusMessage ( QString , unsigned , unsigned , bool ) ) , this , SLOT ( onGotStatusMessage ( QString , unsigned , unsigned , bool ) ) , Qt : : AutoConnection ) ;
2018-08-14 21:38:52 -04:00
connect ( this , SIGNAL ( gotReloadPlaylists ( ) ) , this , SLOT ( onGotReloadPlaylists ( ) ) , Qt : : AutoConnection ) ;
connect ( this , SIGNAL ( gotReloadShaderParams ( ) ) , this , SLOT ( onGotReloadShaderParams ( ) ) , Qt : : AutoConnection ) ;
2018-08-29 11:34:36 -04:00
connect ( this , SIGNAL ( gotReloadCoreOptions ( ) ) , this , SLOT ( onGotReloadCoreOptions ( ) ) , Qt : : AutoConnection ) ;
2018-08-14 21:38:52 -04:00
/* these are always queued */
2018-08-09 11:55:42 -04:00
connect ( this , SIGNAL ( showErrorMessageDeferred ( QString ) ) , this , SLOT ( onShowErrorMessage ( QString ) ) , Qt : : QueuedConnection ) ;
2018-08-16 08:42:40 -04:00
connect ( this , SIGNAL ( showInfoMessageDeferred ( QString ) ) , this , SLOT ( onShowInfoMessage ( QString ) ) , Qt : : QueuedConnection ) ;
2018-08-26 23:24:43 -04:00
connect ( this , SIGNAL ( extractArchiveDeferred ( QString , QString , QString , retro_task_callback_t ) ) , this , SLOT ( onExtractArchive ( QString , QString , QString , retro_task_callback_t ) ) , Qt : : QueuedConnection ) ;
2018-04-30 14:33:05 -04:00
m_timer - > start ( TIMER_MSEC ) ;
statusBar ( ) - > addPermanentWidget ( m_statusLabel ) ;
setCurrentCoreLabel ( ) ;
setCoreActions ( ) ;
/* both of these are necessary to get the folder to scroll to the top of the view */
qApp - > processEvents ( ) ;
QTimer : : singleShot ( 0 , this , SLOT ( onBrowserStartClicked ( ) ) ) ;
m_searchLineEdit - > setFocus ( ) ;
m_loadCoreWindow - > setWindowModality ( Qt : : ApplicationModal ) ;
2018-07-28 23:15:00 -04:00
m_statusMessageElapsedTimer . start ( ) ;
2018-04-30 14:33:05 -04:00
# if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
resizeDocks ( QList < QDockWidget * > ( ) < < m_searchDock , QList < int > ( ) < < 1 , Qt : : Vertical ) ;
# endif
2018-08-06 20:52:47 -04:00
removeUpdateTempFiles ( ) ;
2018-08-26 10:44:55 -04:00
# ifdef HAVE_OPENSSL
2018-08-26 10:40:33 -04:00
{
2018-08-26 18:14:08 -04:00
# if OPENSSL_VERSION_NUMBER >= 0x10100000L
2018-08-26 16:04:01 -04:00
const SSL_METHOD * method = TLS_method ( ) ;
SSL_CTX * ctx = SSL_CTX_new ( method ) ;
2018-08-26 10:40:33 -04:00
2018-08-26 16:04:01 -04:00
if ( ctx )
SSL_CTX_free ( ctx ) ;
# else
const SSL_METHOD * method = TLSv1_method ( ) ;
RARCH_LOG ( " [Qt]: TLS supports %d ciphers. \n " , method - > num_ciphers ( ) ) ;
# endif
2018-08-26 10:40:33 -04:00
RARCH_LOG ( " [Qt]: Using %s \n " , OPENSSL_VERSION_TEXT ) ;
}
2018-08-26 10:44:55 -04:00
# endif
2018-04-30 14:33:05 -04:00
}
MainWindow : : ~ MainWindow ( )
{
if ( m_thumbnailPixmap )
delete m_thumbnailPixmap ;
if ( m_thumbnailPixmap2 )
delete m_thumbnailPixmap2 ;
if ( m_thumbnailPixmap3 )
delete m_thumbnailPixmap3 ;
2019-02-22 09:38:59 -05:00
if ( m_proxyFileModel )
delete m_proxyFileModel ;
2018-12-12 20:45:19 +01:00
}
2018-05-03 02:47:40 -04:00
2018-12-12 20:45:19 +01:00
void MainWindow : : startTimer ( ) {
if ( m_thumbnailTimer - > isActive ( ) )
{
m_thumbnailTimer - > stop ( ) ;
m_thumbnailTimer - > start ( 50 ) ;
}
else
{
m_thumbnailTimer - > start ( 50 ) ;
}
}
void MainWindow : : updateVisibleItems ( ) {
2019-01-07 20:56:23 +01:00
if ( m_currentBrowser = = BROWSER_TYPE_PLAYLISTS & & m_viewType = = VIEW_TYPE_ICONS )
2018-12-12 20:45:19 +01:00
{
QVector < QModelIndex > indexes = m_gridView - > visibleIndexes ( ) ;
2018-12-19 21:28:11 +01:00
int i ;
for ( i = 0 ; i < indexes . size ( ) ; i + + )
2018-12-12 20:45:19 +01:00
{
m_playlistModel - > loadThumbnail ( m_proxyModel - > mapToSource ( indexes . at ( i ) ) ) ;
}
}
}
void MainWindow : : setThumbnailCacheLimit ( int count )
{
if ( count < 1 )
count = 0 ;
m_playlistModel - > setThumbnailCacheLimit ( count ) ;
2018-04-30 14:33:05 -04:00
}
2018-09-01 21:24:59 -04:00
void MainWindow : : onFileSystemDirLoaded ( const QString & path )
{
if ( path . isEmpty ( ) | | m_pendingDirScrollPath . isEmpty ( ) )
return ;
if ( QDir ( path ) = = QDir ( m_pendingDirScrollPath ) )
{
m_pendingDirScrollPath = QString ( ) ;
emit scrollToDownloads ( path ) ;
}
}
2019-01-07 20:56:23 +01:00
/* workaround for columns being resized */
void MainWindow : : onFileBrowserTableDirLoaded ( const QString & path )
{
if ( path . isEmpty ( ) )
return ;
m_fileTableView - > horizontalHeader ( ) - > restoreState ( m_fileTableHeaderState ) ;
}
2018-08-26 17:17:39 -04:00
QVector < QPair < QString , QString > > MainWindow : : getPlaylists ( )
{
QVector < QPair < QString , QString > > playlists ;
int i ;
for ( i = 0 ; i < m_listWidget - > count ( ) ; i + + )
{
QListWidgetItem * item = m_listWidget - > item ( i ) ;
QPair < QString , QString > pair ;
QString label ;
QString path ;
if ( ! item )
continue ;
label = item - > text ( ) ;
path = item - > data ( Qt : : UserRole ) . toString ( ) ;
pair . first = label ;
pair . second = path ;
playlists . append ( pair ) ;
}
return playlists ;
}
2018-08-25 01:00:18 -04:00
void MainWindow : : onItemChanged ( )
{
2018-12-12 20:45:19 +01:00
QModelIndex index = getCurrentContentIndex ( ) ;
m_playlistModel - > reloadThumbnail ( index ) ;
2019-01-07 20:56:23 +01:00
onCurrentItemChanged ( index ) ;
2018-08-25 01:00:18 -04:00
}
2018-08-21 13:39:16 -04:00
QString MainWindow : : getSpecialPlaylistPath ( SpecialPlaylist playlist )
{
switch ( playlist )
{
case SPECIAL_PLAYLIST_HISTORY :
2018-08-26 17:17:39 -04:00
return ( m_historyPlaylistsItem ? m_historyPlaylistsItem - > data ( Qt : : UserRole ) . toString ( ) : QString ( ) ) ;
2018-08-21 13:39:16 -04:00
default :
return QString ( ) ;
}
}
2019-01-07 20:56:23 +01:00
double MainWindow : : lerp ( double x , double y , double a , double b , double d )
{
return a + ( b - a ) * ( ( double ) ( d - x ) / ( double ) ( y - x ) ) ;
2018-08-16 22:58:35 -04:00
}
2018-05-07 02:36:00 -04:00
void MainWindow : : onIconViewClicked ( )
{
setCurrentViewType ( VIEW_TYPE_ICONS ) ;
}
void MainWindow : : onListViewClicked ( )
{
setCurrentViewType ( VIEW_TYPE_LIST ) ;
2019-01-07 20:56:23 +01:00
}
2019-04-01 21:31:46 +02:00
void MainWindow : : onBoxartThumbnailClicked ( )
{
setCurrentThumbnailType ( THUMBNAIL_TYPE_BOXART ) ;
}
void MainWindow : : onScreenshotThumbnailClicked ( )
{
setCurrentThumbnailType ( THUMBNAIL_TYPE_SCREENSHOT ) ;
}
void MainWindow : : onTitleThumbnailClicked ( )
{
setCurrentThumbnailType ( THUMBNAIL_TYPE_TITLE_SCREEN ) ;
}
2019-01-07 20:56:23 +01:00
void MainWindow : : setIconViewZoom ( int zoomValue )
{
m_zoomSlider - > setValue ( zoomValue ) ;
2018-05-07 02:36:00 -04:00
}
2018-12-12 20:45:19 +01:00
void MainWindow : : onZoomValueChanged ( int zoomValue )
2018-08-16 23:14:52 -04:00
{
int newSize = 0 ;
if ( zoomValue < 50 )
newSize = expScale ( lerp ( 0 , 49 , 25 , 49 , zoomValue ) / 50.0 , 102 , 256 ) ;
else
newSize = expScale ( zoomValue / 100.0 , 256 , 1024 ) ;
2018-12-12 20:45:19 +01:00
m_gridView - > setGridSize ( newSize ) ;
2018-05-03 02:47:40 -04:00
2018-12-12 20:45:19 +01:00
m_lastZoomSliderValue = zoomValue ;
2018-05-03 02:47:40 -04:00
}
2018-04-30 14:33:05 -04:00
void MainWindow : : showWelcomeScreen ( )
{
2018-08-08 12:49:29 -04:00
bool dontAsk = false ;
bool answer = false ;
2018-04-30 14:33:05 -04:00
const QString welcomeText = QStringLiteral ( " "
" Welcome to the RetroArch Desktop Menu!<br> \n "
" <br> \n "
2018-04-30 23:02:18 +02:00
" Many settings and actions are currently only available in the familiar Big Picture menu, "
2018-04-30 14:33:05 -04:00
" but this Desktop Menu should be functional for launching content and managing playlists.<br> \n "
" <br> \n "
" Some useful hotkeys for interacting with the Big Picture menu include: \n "
" <ul><li>F1 - Bring up the Big Picture menu</li> \n "
" <li>F - Switch between fullscreen and windowed modes</li> \n "
" <li>F5 - Bring the Desktop Menu back if closed</li> \n "
" <li>Esc - Exit RetroArch</li></ul> \n "
" \n "
2018-04-30 23:02:18 +02:00
" For more hotkeys and their assignments, see:<br> \n "
" Settings -> Input -> Input Hotkey Binds<br> \n "
2018-04-30 14:33:05 -04:00
" <br> \n "
" Documentation for RetroArch, libretro and cores:<br> \n "
" <a href= \" https://docs.libretro.com/ \" >https://docs.libretro.com/</a> " ) ;
2018-08-06 20:52:47 -04:00
if ( ! m_settings - > value ( " show_welcome_screen " , true ) . toBool ( ) )
2018-04-30 14:33:05 -04:00
return ;
2018-08-08 12:49:29 -04:00
answer = showMessageBox ( welcomeText , MainWindow : : MSGBOX_TYPE_QUESTION_OKCANCEL , Qt : : ApplicationModal , true , & dontAsk ) ;
2018-04-30 14:33:05 -04:00
2018-08-08 12:49:29 -04:00
if ( answer & & dontAsk )
m_settings - > setValue ( " show_welcome_screen " , false ) ;
2018-04-30 14:33:05 -04:00
}
const QString & MainWindow : : customThemeString ( ) const
{
return m_customThemeString ;
}
bool MainWindow : : setCustomThemeFile ( QString filePath )
{
if ( filePath . isEmpty ( ) )
{
QMessageBox : : critical ( this , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME ) , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_FILE_PATH_IS_BLANK ) ) ;
return false ;
}
else
{
QFile file ( filePath ) ;
if ( file . exists ( ) )
{
bool opened = file . open ( QIODevice : : ReadOnly ) ;
if ( opened )
{
QByteArray fileArray = file . readAll ( ) ;
QString fileStr = QString : : fromUtf8 ( fileArray ) ;
file . close ( ) ;
if ( fileStr . isEmpty ( ) )
{
QMessageBox : : critical ( this , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME ) , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_FILE_IS_EMPTY ) ) ;
return false ;
}
else
setCustomThemeString ( fileStr ) ;
}
else
{
QMessageBox : : critical ( this , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME ) , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_FILE_READ_OPEN_FAILED ) ) ;
return false ;
}
}
else
{
QMessageBox : : critical ( this , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_CUSTOM_THEME ) , msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST ) ) ;
return false ;
}
}
return true ;
}
void MainWindow : : setCustomThemeString ( QString qss )
{
m_customThemeString = qss ;
}
2018-08-08 12:49:29 -04:00
bool MainWindow : : showMessageBox ( QString msg , MessageBoxType msgType , Qt : : WindowModality modality , bool showDontAsk , bool * dontAsk )
2018-04-30 14:33:05 -04:00
{
2018-05-07 00:07:12 -04:00
QPointer < QMessageBox > msgBoxPtr ;
2018-04-30 14:33:05 -04:00
QMessageBox * msgBox = NULL ;
QCheckBox * checkBox = NULL ;
2018-05-07 00:07:12 -04:00
msgBoxPtr = new QMessageBox ( this ) ;
msgBox = msgBoxPtr . data ( ) ;
2018-04-30 14:33:05 -04:00
msgBox - > setWindowModality ( modality ) ;
msgBox - > setTextFormat ( Qt : : RichText ) ;
2018-08-03 21:14:27 -04:00
msgBox - > setTextInteractionFlags ( Qt : : TextBrowserInteraction ) ;
2018-04-30 14:33:05 -04:00
2018-07-26 00:38:15 -04:00
if ( showDontAsk )
{
checkBox = new QCheckBox ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_DONT_SHOW_AGAIN ) , msgBox ) ;
/* QMessageBox::setCheckBox() is available since 5.2 */
msgBox - > setCheckBox ( checkBox ) ;
}
2018-04-30 14:33:05 -04:00
switch ( msgType )
{
case MSGBOX_TYPE_INFO :
{
msgBox - > setIcon ( QMessageBox : : Information ) ;
msgBox - > setWindowTitle ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_INFORMATION ) ) ;
break ;
}
case MSGBOX_TYPE_WARNING :
{
msgBox - > setIcon ( QMessageBox : : Warning ) ;
msgBox - > setWindowTitle ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_WARNING ) ) ;
break ;
}
case MSGBOX_TYPE_ERROR :
{
msgBox - > setIcon ( QMessageBox : : Critical ) ;
msgBox - > setWindowTitle ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_ERROR ) ) ;
break ;
}
2018-08-08 12:49:29 -04:00
case MSGBOX_TYPE_QUESTION_YESNO :
{
msgBox - > setIcon ( QMessageBox : : Question ) ;
msgBox - > setWindowTitle ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_QUESTION ) ) ;
msgBox - > setStandardButtons ( QMessageBox : : Yes | QMessageBox : : No ) ;
break ;
}
case MSGBOX_TYPE_QUESTION_OKCANCEL :
2018-07-26 00:38:15 -04:00
{
msgBox - > setIcon ( QMessageBox : : Question ) ;
msgBox - > setWindowTitle ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_QUESTION ) ) ;
msgBox - > setStandardButtons ( QMessageBox : : Ok | QMessageBox : : Cancel ) ;
break ;
}
2018-04-30 14:33:05 -04:00
default :
break ;
}
msgBox - > setText ( msg ) ;
msgBox - > exec ( ) ;
2018-05-06 20:50:54 -04:00
if ( ! msgBoxPtr )
return true ;
2018-08-08 12:49:29 -04:00
if ( msgBox - > result ( ) ! = QMessageBox : : Ok & & msgBox - > result ( ) ! = QMessageBox : : Yes )
2018-07-26 00:38:15 -04:00
return false ;
2018-08-08 12:49:29 -04:00
if ( checkBox )
if ( dontAsk )
* dontAsk = checkBox - > isChecked ( ) ;
2018-04-30 14:33:05 -04:00
return true ;
}
void MainWindow : : onFileBrowserTreeContextMenuRequested ( const QPoint & )
{
# ifdef HAVE_LIBRETRODB
2018-05-06 20:50:54 -04:00
QPointer < QAction > action ;
2018-04-30 14:33:05 -04:00
QList < QAction * > actions ;
QScopedPointer < QAction > scanAction ;
QDir dir ;
2018-08-19 11:05:25 -04:00
QString currentDirString = QDir : : toNativeSeparators ( m_dirModel - > filePath ( m_dirTree - > currentIndex ( ) ) ) ;
2018-04-30 14:33:05 -04:00
settings_t * settings = config_get_ptr ( ) ;
QByteArray dirArray ;
const char * fullpath = NULL ;
if ( currentDirString . isEmpty ( ) )
return ;
dir = currentDirString ;
if ( ! dir . exists ( ) )
return ;
/* default NULL parameter for parent wasn't added until 5.7 */
scanAction . reset ( new QAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_SCAN_DIRECTORY ) , 0 ) ) ;
actions . append ( scanAction . data ( ) ) ;
action = QMenu : : exec ( actions , QCursor : : pos ( ) , NULL , m_dirTree ) ;
if ( ! action )
return ;
dirArray = currentDirString . toUtf8 ( ) ;
fullpath = dirArray . constData ( ) ;
task_push_dbscan (
settings - > paths . directory_playlist ,
settings - > paths . path_content_database ,
fullpath , true ,
m_settings - > value ( " show_hidden_files " , true ) . toBool ( ) ,
scan_finished_handler ) ;
# endif
}
void MainWindow : : showStatusMessage ( QString msg , unsigned priority , unsigned duration , bool flush )
{
emit gotStatusMessage ( msg , priority , duration , flush ) ;
}
void MainWindow : : onGotStatusMessage ( QString msg , unsigned priority , unsigned duration , bool flush )
{
int msecDuration = 0 ;
QScreen * screen = qApp - > primaryScreen ( ) ;
QStatusBar * status = statusBar ( ) ;
2018-05-06 20:50:54 -04:00
Q_UNUSED ( priority )
2019-01-07 20:56:23 +01:00
if ( msg . isEmpty ( ) )
return ;
2018-04-30 14:33:05 -04:00
if ( ! status )
return ;
if ( screen )
{
msecDuration = ( duration / screen - > refreshRate ( ) ) * 1000 ;
}
if ( msecDuration < = 0 )
msecDuration = 1000 ;
if ( status - > currentMessage ( ) . isEmpty ( ) | | flush )
2018-07-28 23:15:00 -04:00
{
if ( m_statusMessageElapsedTimer . elapsed ( ) > = STATUS_MSG_THROTTLE_MSEC )
{
qint64 msgDuration = qMax ( msecDuration , STATUS_MSG_THROTTLE_MSEC ) ;
m_statusMessageElapsedTimer . restart ( ) ;
status - > showMessage ( msg , msgDuration ) ;
}
}
2018-04-30 14:33:05 -04:00
}
2018-08-14 21:38:52 -04:00
void MainWindow : : deferReloadShaderParams ( )
{
emit gotReloadShaderParams ( ) ;
}
2018-08-18 00:33:52 -04:00
void MainWindow : : onShaderParamsClicked ( )
{
if ( ! m_shaderParamsDialog )
return ;
m_shaderParamsDialog - > show ( ) ;
onGotReloadShaderParams ( ) ;
}
2018-08-29 11:34:36 -04:00
void MainWindow : : onCoreOptionsClicked ( )
{
if ( ! m_coreOptionsDialog )
return ;
m_coreOptionsDialog - > show ( ) ;
onGotReloadCoreOptions ( ) ;
}
2018-08-14 21:38:52 -04:00
void MainWindow : : onGotReloadShaderParams ( )
{
if ( m_shaderParamsDialog & & m_shaderParamsDialog - > isVisible ( ) )
2018-08-18 00:33:52 -04:00
m_shaderParamsDialog - > reload ( ) ;
2018-08-14 21:38:52 -04:00
}
2018-08-29 11:34:36 -04:00
void MainWindow : : onGotReloadCoreOptions ( )
{
if ( m_coreOptionsDialog & & m_coreOptionsDialog - > isVisible ( ) )
m_coreOptionsDialog - > reload ( ) ;
}
2018-04-30 14:33:05 -04:00
void MainWindow : : appendLogMessage ( const QString & msg )
{
emit gotLogMessage ( msg ) ;
}
void MainWindow : : onGotLogMessage ( const QString & msg )
{
QString newMsg = msg ;
if ( newMsg . at ( newMsg . size ( ) - 1 ) = = ' \n ' )
newMsg . chop ( 1 ) ;
m_logTextEdit - > appendMessage ( newMsg ) ;
}
void MainWindow : : onLaunchWithComboBoxIndexChanged ( int )
{
2018-05-06 01:36:47 -04:00
QVector < QHash < QString , QString > > infoList = getCoreInfo ( ) ;
2018-04-30 14:33:05 -04:00
QString coreInfoText ;
QVariantMap coreMap = m_launchWithComboBox - > currentData ( Qt : : UserRole ) . value < QVariantMap > ( ) ;
CoreSelection coreSelection = static_cast < CoreSelection > ( coreMap . value ( " core_selection " ) . toInt ( ) ) ;
int i = 0 ;
if ( infoList . count ( ) = = 0 )
return ;
for ( i = 0 ; i < infoList . count ( ) ; i + + )
{
const QHash < QString , QString > & hash = infoList . at ( i ) ;
const QString & key = hash . value ( " html_key " , hash . value ( " key " ) ) ;
const QString & value = hash . value ( " html_value " , hash . value ( " value " ) ) ;
if ( ! key . isEmpty ( ) )
coreInfoText + = key ;
if ( ! value . isEmpty ( ) )
{
if ( ! key . isEmpty ( ) )
coreInfoText + = " " ;
coreInfoText + = value ;
}
if ( i < infoList . count ( ) - 1 )
coreInfoText + = " <br> \n " ;
}
m_coreInfoLabel - > setText ( coreInfoText ) ;
if ( coreSelection = = CORE_SELECTION_LOAD_CORE )
{
onLoadCoreClicked ( ) ;
}
else
{
m_loadCoreWindow - > setProperty ( " last_launch_with_index " , m_launchWithComboBox - > currentIndex ( ) ) ;
}
}
MainWindow : : Theme MainWindow : : getThemeFromString ( QString themeString )
{
if ( themeString = = " default " )
return THEME_SYSTEM_DEFAULT ;
else if ( themeString = = " dark " )
return THEME_DARK ;
else if ( themeString = = " custom " )
return THEME_CUSTOM ;
return THEME_SYSTEM_DEFAULT ;
}
QString MainWindow : : getThemeString ( Theme theme )
{
switch ( theme )
{
case THEME_SYSTEM_DEFAULT :
return " default " ;
case THEME_DARK :
return " dark " ;
case THEME_CUSTOM :
return " custom " ;
default :
break ;
}
return " default " ;
}
MainWindow : : Theme MainWindow : : theme ( )
{
return m_currentTheme ;
}
void MainWindow : : setTheme ( Theme theme )
{
m_currentTheme = theme ;
2018-12-23 00:45:00 +01:00
setDefaultCustomProperties ( ) ;
2018-04-30 14:33:05 -04:00
switch ( theme )
{
case THEME_SYSTEM_DEFAULT :
{
2018-07-25 01:43:57 -04:00
qApp - > setStyleSheet ( qt_theme_default_stylesheet . arg ( m_settings - > value ( " highlight_color " , " palette(highlight) " ) . toString ( ) ) ) ;
2018-04-30 14:33:05 -04:00
break ;
}
case THEME_DARK :
{
qApp - > setStyleSheet ( qt_theme_dark_stylesheet . arg ( m_settings - > value ( " highlight_color " , " palette(highlight) " ) . toString ( ) ) ) ;
break ;
}
case THEME_CUSTOM :
{
qApp - > setStyleSheet ( m_customThemeString ) ;
break ;
}
default :
break ;
}
2019-03-27 02:37:34 +01:00
# ifdef HAVE_MENU
m_viewOptionsDialog - > repaintIcons ( ) ;
# endif
2018-04-30 14:33:05 -04:00
}
2018-12-23 00:45:00 +01:00
void MainWindow : : setDefaultCustomProperties ( )
{
m_gridView - > setLayout ( QString ( DEFAULT_GRID_LAYOUT ) ) ;
m_gridView - > setSpacing ( DEFAULT_GRID_SPACING ) ;
m_gridItem . setThumbnailVerticalAlign ( QString ( DEFAULT_GRID_ITEM_THUMBNAIL_ALIGNMENT ) ) ;
m_gridItem . setPadding ( DEFAULT_GRID_ITEM_MARGIN ) ;
}
2018-12-12 20:45:19 +01:00
void MainWindow : : changeThumbnailType ( ThumbnailType type )
{
m_playlistModel - > setThumbnailType ( type ) ;
updateVisibleItems ( ) ;
m_gridView - > viewport ( ) - > update ( ) ;
}
2019-01-23 19:28:59 +01:00
QString MainWindow : : changeThumbnail ( const QImage & image , QString type )
{
QHash < QString , QString > hash = getCurrentContentHash ( ) ;
2019-01-23 21:21:30 +01:00
QString dirString = m_playlistModel - > getPlaylistThumbnailsDir ( hash [ " db_name " ] ) + " / " + type ;
QString thumbPath = dirString + " / " + m_playlistModel - > getSanitizedThumbnailName ( hash [ " label_noext " ] ) ;
2019-01-23 19:28:59 +01:00
QByteArray dirArray = QDir : : toNativeSeparators ( dirString ) . toUtf8 ( ) ;
const char * dirData = dirArray . constData ( ) ;
QByteArray thumbArray = QDir : : toNativeSeparators ( thumbPath ) . toUtf8 ( ) ;
const char * thumbData = thumbArray . constData ( ) ;
QDir dir ( dirString ) ;
int quality = - 1 ;
QImage scaledImage ( image ) ;
if ( ! dir . exists ( ) )
{
if ( dir . mkpath ( " . " ) )
RARCH_LOG ( " [Qt]: Created directory: %s \n " , dirData ) ;
else
{
RARCH_ERR ( " [Qt]: Could not create directory: %s \n " , dirData ) ;
return QString ( ) ;
}
}
if ( m_settings - > contains ( " thumbnail_max_size " ) )
{
int size = m_settings - > value ( " thumbnail_max_size " , 512 ) . toInt ( ) ;
if ( size ! = 0 )
scaledImage = image . scaled ( size , size , Qt : : KeepAspectRatio , Qt : : SmoothTransformation ) ;
}
if ( m_settings - > contains ( " thumbnail_quality " ) )
quality = m_settings - > value ( " thumbnail_quality " , - 1 ) . toInt ( ) ;
if ( scaledImage . save ( thumbPath , " png " , quality ) )
{
RARCH_LOG ( " [Qt]: Saved image: %s \n " , thumbData ) ;
m_playlistModel - > reloadThumbnailPath ( thumbPath ) ;
updateVisibleItems ( ) ;
return thumbPath ;
}
RARCH_ERR ( " [Qt]: Could not save image: %s \n " , thumbData ) ;
return QString ( ) ;
}
void MainWindow : : onThumbnailDropped ( const QImage & image , ThumbnailType thumbnailType )
{
switch ( thumbnailType )
{
case THUMBNAIL_TYPE_BOXART :
{
QString path = changeThumbnail ( image , THUMBNAIL_BOXART ) ;
if ( path . isNull ( ) )
return ;
if ( m_thumbnailPixmap )
delete m_thumbnailPixmap ;
m_thumbnailPixmap = new QPixmap ( path ) ;
2019-01-30 21:26:33 +01:00
onResizeThumbnailOne ( * m_thumbnailPixmap , true ) ;
2019-01-23 19:28:59 +01:00
break ;
}
case THUMBNAIL_TYPE_TITLE_SCREEN :
{
QString path = changeThumbnail ( image , THUMBNAIL_TITLE ) ;
if ( path . isNull ( ) )
return ;
if ( m_thumbnailPixmap2 )
delete m_thumbnailPixmap2 ;
m_thumbnailPixmap2 = new QPixmap ( path ) ;
2019-01-30 21:26:33 +01:00
onResizeThumbnailTwo ( * m_thumbnailPixmap2 , true ) ;
2019-01-23 19:28:59 +01:00
break ;
}
case THUMBNAIL_TYPE_SCREENSHOT :
{
QString path = changeThumbnail ( image , THUMBNAIL_SCREENSHOT ) ;
if ( path . isNull ( ) )
return ;
if ( m_thumbnailPixmap3 )
delete m_thumbnailPixmap3 ;
m_thumbnailPixmap3 = new QPixmap ( path ) ;
2019-01-30 21:26:33 +01:00
onResizeThumbnailThree ( * m_thumbnailPixmap3 , true ) ;
2019-01-23 19:28:59 +01:00
break ;
}
}
}
2018-05-06 01:36:47 -04:00
QVector < QHash < QString , QString > > MainWindow : : getCoreInfo ( )
2018-04-30 14:33:05 -04:00
{
2018-05-06 01:36:47 -04:00
QVector < QHash < QString , QString > > infoList ;
2018-04-30 14:33:05 -04:00
QHash < QString , QString > currentCore = getSelectedCore ( ) ;
core_info_list_t * core_info_list = NULL ;
const core_info_t * core_info = NULL ;
unsigned i = 0 ;
core_info_get_list ( & core_info_list ) ;
2018-05-01 18:17:28 -04:00
if ( ! core_info_list | | core_info_list - > count = = 0 )
return infoList ;
2018-04-30 14:33:05 -04:00
for ( i = 0 ; i < core_info_list - > count ; i + + )
{
const core_info_t * core = & core_info_list - > list [ i ] ;
if ( currentCore [ " core_path " ] = = core - > path )
{
core_info = core ;
break ;
}
}
if ( currentCore [ " core_path " ] . isEmpty ( ) | | ! core_info | | ! core_info - > config_data )
{
QHash < QString , QString > hash ;
hash [ " key " ] = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_NO_CORE_INFORMATION_AVAILABLE ) ;
hash [ " value " ] = " " ;
infoList . append ( hash ) ;
return infoList ;
}
if ( core_info - > core_name )
{
QHash < QString , QString > hash ;
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_CORE_NAME ) ) + " : " ;
hash [ " value " ] = core_info - > core_name ;
infoList . append ( hash ) ;
}
if ( core_info - > display_name )
{
QHash < QString , QString > hash ;
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_CORE_LABEL ) ) + " : " ;
hash [ " value " ] = core_info - > display_name ;
infoList . append ( hash ) ;
}
if ( core_info - > systemname )
{
QHash < QString , QString > hash ;
2018-10-30 17:11:07 +01:00
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_SYSTEM_NAME ) ) + " : " ;
2018-04-30 14:33:05 -04:00
hash [ " value " ] = core_info - > systemname ;
infoList . append ( hash ) ;
}
if ( core_info - > system_manufacturer )
{
QHash < QString , QString > hash ;
2018-10-30 17:11:07 +01:00
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_SYSTEM_MANUFACTURER ) ) + " : " ;
2018-04-30 14:33:05 -04:00
hash [ " value " ] = core_info - > system_manufacturer ;
infoList . append ( hash ) ;
}
if ( core_info - > categories_list )
{
QHash < QString , QString > hash ;
QString categories ;
for ( i = 0 ; i < core_info - > categories_list - > size ; i + + )
{
categories + = core_info - > categories_list - > elems [ i ] . data ;
if ( i < core_info - > categories_list - > size - 1 )
categories + = " , " ;
}
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_CATEGORIES ) ) + " : " ;
hash [ " value " ] = categories ;
infoList . append ( hash ) ;
}
if ( core_info - > authors_list )
{
QHash < QString , QString > hash ;
QString authors ;
for ( i = 0 ; i < core_info - > authors_list - > size ; i + + )
{
authors + = core_info - > authors_list - > elems [ i ] . data ;
if ( i < core_info - > authors_list - > size - 1 )
authors + = " , " ;
}
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_AUTHORS ) ) + " : " ;
hash [ " value " ] = authors ;
infoList . append ( hash ) ;
}
if ( core_info - > permissions_list )
{
QHash < QString , QString > hash ;
QString permissions ;
for ( i = 0 ; i < core_info - > permissions_list - > size ; i + + )
{
permissions + = core_info - > permissions_list - > elems [ i ] . data ;
if ( i < core_info - > permissions_list - > size - 1 )
permissions + = " , " ;
}
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_PERMISSIONS ) ) + " : " ;
hash [ " value " ] = permissions ;
infoList . append ( hash ) ;
}
if ( core_info - > licenses_list )
{
QHash < QString , QString > hash ;
QString licenses ;
for ( i = 0 ; i < core_info - > licenses_list - > size ; i + + )
{
licenses + = core_info - > licenses_list - > elems [ i ] . data ;
if ( i < core_info - > licenses_list - > size - 1 )
licenses + = " , " ;
}
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_LICENSES ) ) + " : " ;
hash [ " value " ] = licenses ;
infoList . append ( hash ) ;
}
if ( core_info - > supported_extensions_list )
{
QHash < QString , QString > hash ;
QString supported_extensions ;
for ( i = 0 ; i < core_info - > supported_extensions_list - > size ; i + + )
{
supported_extensions + = core_info - > supported_extensions_list - > elems [ i ] . data ;
if ( i < core_info - > supported_extensions_list - > size - 1 )
supported_extensions + = " , " ;
}
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_SUPPORTED_EXTENSIONS ) ) + " : " ;
hash [ " value " ] = supported_extensions ;
infoList . append ( hash ) ;
}
if ( core_info - > firmware_count > 0 )
{
core_info_ctx_firmware_t firmware_info ;
bool update_missing_firmware = false ;
bool set_missing_firmware = false ;
settings_t * settings = config_get_ptr ( ) ;
firmware_info . path = core_info - > path ;
firmware_info . directory . system = settings - > paths . directory_system ;
rarch_ctl ( RARCH_CTL_UNSET_MISSING_BIOS , NULL ) ;
update_missing_firmware = core_info_list_update_missing_firmware ( & firmware_info , & set_missing_firmware ) ;
if ( set_missing_firmware )
rarch_ctl ( RARCH_CTL_SET_MISSING_BIOS , NULL ) ;
if ( update_missing_firmware )
{
QHash < QString , QString > hash ;
hash [ " key " ] = QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_CORE_INFO_FIRMWARE ) ) + " : " ;
hash [ " value " ] = " " ;
infoList . append ( hash ) ;
/* FIXME: This looks hacky and probably
* needs to be improved for good translation support . */
for ( i = 0 ; i < core_info - > firmware_count ; i + + )
{
if ( core_info - > firmware [ i ] . desc )
{
QString labelText = " (!) " ;
QString valueText ;
QHash < QString , QString > hash ;
bool missing = false ;
if ( core_info - > firmware [ i ] . missing )
{
missing = true ;
labelText + = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_MISSING ) ;
}
else
{
labelText + = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_PRESENT ) ;
}
labelText + = " , " ;
if ( core_info - > firmware [ i ] . optional )
{
labelText + = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_OPTIONAL ) ;
}
else
{
labelText + = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_REQUIRED ) ;
}
labelText + = " : " ;
if ( core_info - > firmware [ i ] . desc )
{
valueText = core_info - > firmware [ i ] . desc ;
}
else
{
valueText = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_RDB_ENTRY_NAME ) ;
}
hash [ " key " ] = labelText ;
hash [ " value " ] = valueText ;
if ( missing )
{
QString style = " font-weight: bold; color: #ff0000 " ;
hash [ " label_style " ] = style ;
hash [ " value_style " ] = style ;
hash [ " html_key " ] = " <b><font color= \" #ff0000 \" > " + hash [ " key " ] + " </font></b> " ;
hash [ " html_value " ] = " <b><font color= \" #ff0000 \" > " + hash [ " value " ] + " </font></b> " ;
}
else
{
QString style = " font-weight: bold; color: rgb(0, 175, 0) " ;
hash [ " label_style " ] = style ;
hash [ " value_style " ] = style ;
hash [ " html_key " ] = " <b><font color= \" #00af00 \" > " + hash [ " key " ] + " </font></b> " ;
hash [ " html_value " ] = " <b><font color= \" #00af00 \" > " + hash [ " value " ] + " </font></b> " ;
}
infoList . append ( hash ) ;
}
}
}
}
if ( core_info - > notes )
{
for ( i = 0 ; i < core_info - > note_list - > size ; i + + )
{
QHash < QString , QString > hash ;
hash [ " key " ] = " " ;
hash [ " value " ] = core_info - > note_list - > elems [ i ] . data ;
infoList . append ( hash ) ;
}
}
return infoList ;
}
void MainWindow : : onSearchResetClicked ( )
{
m_searchLineEdit - > clear ( ) ;
onSearchEnterPressed ( ) ;
}
QToolButton * MainWindow : : coreInfoPushButton ( )
{
return m_coreInfoPushButton ;
}
void MainWindow : : onTreeViewItemsSelected ( QModelIndexList selectedIndexes )
{
QString dir ;
if ( selectedIndexes . isEmpty ( ) )
return ;
dir = m_dirModel - > filePath ( selectedIndexes . first ( ) ) ;
selectBrowserDir ( dir ) ;
}
2019-01-07 20:56:23 +01:00
void MainWindow : : onFileDoubleClicked ( const QModelIndex & proxyIndex )
{
const QModelIndex index = m_proxyFileModel - > mapToSource ( proxyIndex ) ;
if ( m_fileModel - > isDir ( index ) )
m_dirTree - > setCurrentIndex ( m_dirModel - > index ( m_fileModel - > filePath ( index ) ) ) ;
else
loadContent ( getFileContentHash ( index ) ) ;
}
2018-04-30 14:33:05 -04:00
void MainWindow : : selectBrowserDir ( QString path )
{
2019-01-07 20:56:23 +01:00
if ( ! path . isEmpty ( ) )
{
QModelIndex sourceIndex = m_fileModel - > setRootPath ( path ) ;
QModelIndex proxyIndex = m_proxyFileModel - > mapFromSource ( sourceIndex ) ;
m_fileTableHeaderState = m_fileTableView - > horizontalHeader ( ) - > saveState ( ) ;
if ( proxyIndex . isValid ( ) )
{
m_fileTableView - > setRootIndex ( proxyIndex ) ;
}
else
{
/* the directory is filtered out. Remove the filter for a moment. FIXME find a way to not have to do this (not filtering dirs is one). */
m_proxyFileModel - > setFilterRegExp ( QRegExp ( ) ) ;
m_fileTableView - > setRootIndex ( m_proxyFileModel - > mapFromSource ( sourceIndex ) ) ;
m_proxyFileModel - > setFilterRegExp ( m_searchRegExp ) ;
}
}
2019-01-07 23:50:21 +01:00
setCoreActions ( ) ;
2018-04-30 14:33:05 -04:00
}
QTabWidget * MainWindow : : browserAndPlaylistTabWidget ( )
{
return m_browserAndPlaylistTabWidget ;
}
2018-12-12 20:45:19 +01:00
void MainWindow : : onDropWidgetEnterPressed ( )
2018-04-30 14:33:05 -04:00
{
2018-09-17 23:12:08 -04:00
# if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
2018-09-16 21:34:28 -04:00
/* entry is being renamed, ignore this enter press */
2018-12-12 20:45:19 +01:00
if ( m_tableView - > isPersistentEditorOpen ( m_tableView - > currentIndex ( ) ) )
2018-09-17 23:12:08 -04:00
# else
/* we can only check if any editor at all is open */
2018-12-12 20:45:19 +01:00
if ( m_tableView - > isEditorOpen ( ) )
2018-09-17 23:12:08 -04:00
# endif
2018-09-16 21:34:28 -04:00
return ;
2018-04-30 14:33:05 -04:00
onRunClicked ( ) ;
}
2018-12-12 20:45:19 +01:00
QModelIndex MainWindow : : getCurrentContentIndex ( )
2018-07-28 11:48:24 -04:00
{
2018-12-12 20:45:19 +01:00
if ( m_viewType = = VIEW_TYPE_LIST )
{
return m_tableView - > currentIndex ( ) ;
}
else if ( m_viewType = = VIEW_TYPE_ICONS )
{
return m_gridView - > currentIndex ( ) ;
}
return QModelIndex ( ) ;
2018-07-28 11:48:24 -04:00
}
2018-07-28 22:34:00 -04:00
QHash < QString , QString > MainWindow : : getCurrentContentHash ( )
{
2018-12-12 20:45:19 +01:00
return getCurrentContentIndex ( ) . data ( PlaylistModel : : HASH ) . value < QHash < QString , QString > > ( ) ;
2018-07-28 22:34:00 -04:00
}
2019-01-07 20:56:23 +01:00
QHash < QString , QString > MainWindow : : getFileContentHash ( const QModelIndex & index )
{
QFileInfo fileInfo = m_fileModel - > fileInfo ( index ) ;
QHash < QString , QString > hash ;
2019-03-04 17:27:58 +01:00
hash [ " path " ] = QDir : : toNativeSeparators ( m_fileModel - > filePath ( index ) ) ;
2019-01-07 20:56:23 +01:00
hash [ " label " ] = hash [ " path " ] ;
hash [ " label_noext " ] = fileInfo . completeBaseName ( ) ;
hash [ " db_name " ] = fileInfo . dir ( ) . dirName ( ) ;
return hash ;
}
2018-12-12 20:45:19 +01:00
void MainWindow : : onContentItemDoubleClicked ( const QModelIndex & index )
{
Q_UNUSED ( index ) ;
onRunClicked ( ) ;
}
2018-04-30 14:33:05 -04:00
void MainWindow : : onStartCoreClicked ( )
{
content_ctx_info_t content_info ;
content_info . argc = 0 ;
content_info . argv = NULL ;
content_info . args = NULL ;
content_info . environ_get = NULL ;
path_clear ( RARCH_PATH_BASENAME ) ;
if ( ! task_push_start_current_core ( & content_info ) )
{
QMessageBox : : critical ( this , msg_hash_to_str ( MSG_ERROR ) , msg_hash_to_str ( MSG_FAILED_TO_LOAD_CONTENT ) ) ;
}
}
QHash < QString , QString > MainWindow : : getSelectedCore ( )
{
QVariantMap coreMap = m_launchWithComboBox - > currentData ( Qt : : UserRole ) . value < QVariantMap > ( ) ;
CoreSelection coreSelection = static_cast < CoreSelection > ( coreMap . value ( " core_selection " ) . toInt ( ) ) ;
QHash < QString , QString > coreHash ;
QHash < QString , QString > contentHash ;
2018-07-23 11:17:58 -04:00
ViewType viewType = getCurrentViewType ( ) ;
2018-04-30 14:33:05 -04:00
2018-12-12 20:45:19 +01:00
if ( viewType = = VIEW_TYPE_LIST )
contentHash = m_tableView - > currentIndex ( ) . data ( PlaylistModel : : HASH ) . value < QHash < QString , QString > > ( ) ;
2018-07-23 11:17:58 -04:00
else if ( viewType = = VIEW_TYPE_ICONS )
2018-12-12 20:45:19 +01:00
contentHash = m_gridView - > currentIndex ( ) . data ( PlaylistModel : : HASH ) . value < QHash < QString , QString > > ( ) ;
2018-07-28 11:48:24 -04:00
else
return coreHash ;
2018-04-30 14:33:05 -04:00
switch ( coreSelection )
{
case CORE_SELECTION_CURRENT :
{
coreHash [ " core_path " ] = path_get ( RARCH_PATH_CORE ) ;
break ;
}
case CORE_SELECTION_PLAYLIST_SAVED :
{
2018-07-24 17:07:17 -04:00
if ( contentHash . isEmpty ( ) | | contentHash [ " core_path " ] . isEmpty ( ) )
2018-04-30 14:33:05 -04:00
break ;
coreHash [ " core_path " ] = contentHash [ " core_path " ] ;
break ;
}
case CORE_SELECTION_PLAYLIST_DEFAULT :
{
2018-05-06 01:36:47 -04:00
QVector < QHash < QString , QString > > cores ;
2018-04-30 14:33:05 -04:00
int i = 0 ;
2018-07-24 17:07:17 -04:00
if ( contentHash . isEmpty ( ) | | contentHash [ " db_name " ] . isEmpty ( ) )
2018-04-30 14:33:05 -04:00
break ;
cores = getPlaylistDefaultCores ( ) ;
for ( i = 0 ; i < cores . count ( ) ; i + + )
{
if ( cores [ i ] [ " playlist_filename " ] = = contentHash [ " db_name " ] )
{
if ( cores [ i ] [ " core_path " ] . isEmpty ( ) )
break ;
coreHash [ " core_path " ] = cores [ i ] [ " core_path " ] ;
break ;
}
}
break ;
}
default :
break ;
}
return coreHash ;
}
2018-07-23 11:17:58 -04:00
/* the hash typically has the following keys:
path - absolute path to the content file
core_path - absolute path to the core , or " DETECT " to ask the user
db_name - the display name of the rdb database this content is from
label - the display name of the content , usually comes from the database
crc32 - an upper - case , 8 byte string representation of the hex CRC32 checksum ( e . g . ABCDEF12 ) followed by " |crc "
core_name - the display name of the core , or " DETECT " if unknown
label_noext - the display name of the content that is guaranteed not to contain a file extension
*/
void MainWindow : : loadContent ( const QHash < QString , QString > & contentHash )
2018-04-30 14:33:05 -04:00
{
content_ctx_info_t content_info ;
QByteArray corePathArray ;
QByteArray contentPathArray ;
QByteArray contentLabelArray ;
const char * corePath = NULL ;
const char * contentPath = NULL ;
const char * contentLabel = NULL ;
QVariantMap coreMap = m_launchWithComboBox - > currentData ( Qt : : UserRole ) . value < QVariantMap > ( ) ;
CoreSelection coreSelection = static_cast < CoreSelection > ( coreMap . value ( " core_selection " ) . toInt ( ) ) ;
2018-04-30 20:33:28 -04:00
if ( m_pendingRun )
coreSelection = CORE_SELECTION_CURRENT ;
2018-04-30 14:33:05 -04:00
if ( coreSelection = = CORE_SELECTION_ASK )
{
QStringList extensionFilters ;
2018-07-23 11:17:58 -04:00
if ( contentHash . contains ( " path " ) )
2018-04-30 14:33:05 -04:00
{
2018-07-23 11:17:58 -04:00
int lastIndex = contentHash [ " path " ] . lastIndexOf ( ' . ' ) ;
QString extensionStr ;
QByteArray pathArray = contentHash [ " path " ] . toUtf8 ( ) ;
const char * pathData = pathArray . constData ( ) ;
2018-04-30 14:33:05 -04:00
2018-07-23 11:17:58 -04:00
if ( lastIndex > = 0 )
2018-04-30 14:33:05 -04:00
{
2018-07-23 11:17:58 -04:00
extensionStr = contentHash [ " path " ] . mid ( lastIndex + 1 ) ;
2018-04-30 14:33:05 -04:00
2018-07-23 11:17:58 -04:00
if ( ! extensionStr . isEmpty ( ) )
2018-04-30 14:33:05 -04:00
{
2018-07-23 11:17:58 -04:00
extensionFilters . append ( extensionStr . toLower ( ) ) ;
2018-04-30 14:33:05 -04:00
}
2018-07-23 11:17:58 -04:00
}
2018-04-30 14:33:05 -04:00
2018-07-23 11:17:58 -04:00
if ( path_is_compressed_file ( pathData ) )
{
unsigned i = 0 ;
struct string_list * list = file_archive_get_file_list ( pathData , NULL ) ;
2018-04-30 14:33:05 -04:00
2018-07-23 11:17:58 -04:00
if ( list )
{
if ( list - > size > 0 )
2018-04-30 14:33:05 -04:00
{
2018-07-23 11:17:58 -04:00
for ( i = 0 ; i < list - > size ; i + + )
2018-04-30 14:33:05 -04:00
{
2018-07-23 11:17:58 -04:00
const char * filePath = list - > elems [ i ] . data ;
const char * extension = path_get_extension ( filePath ) ;
2018-04-30 14:33:05 -04:00
2018-07-23 11:17:58 -04:00
if ( ! extensionFilters . contains ( extension , Qt : : CaseInsensitive ) )
extensionFilters . append ( extension ) ;
2018-04-30 14:33:05 -04:00
}
}
2018-07-23 11:17:58 -04:00
string_list_free ( list ) ;
2018-04-30 14:33:05 -04:00
}
}
}
m_pendingRun = true ;
onLoadCoreClicked ( extensionFilters ) ;
return ;
}
switch ( coreSelection )
{
case CORE_SELECTION_CURRENT :
{
corePathArray = path_get ( RARCH_PATH_CORE ) ;
contentPathArray = contentHash [ " path " ] . toUtf8 ( ) ;
contentLabelArray = contentHash [ " label_noext " ] . toUtf8 ( ) ;
break ;
}
case CORE_SELECTION_PLAYLIST_SAVED :
{
corePathArray = contentHash [ " core_path " ] . toUtf8 ( ) ;
contentPathArray = contentHash [ " path " ] . toUtf8 ( ) ;
contentLabelArray = contentHash [ " label_noext " ] . toUtf8 ( ) ;
break ;
}
case CORE_SELECTION_PLAYLIST_DEFAULT :
{
2018-05-06 01:36:47 -04:00
QVector < QHash < QString , QString > > cores = getPlaylistDefaultCores ( ) ;
2018-04-30 14:33:05 -04:00
int i = 0 ;
for ( i = 0 ; i < cores . count ( ) ; i + + )
{
if ( cores [ i ] [ " playlist_filename " ] = = contentHash [ " db_name " ] )
{
corePathArray = cores [ i ] [ " core_path " ] . toUtf8 ( ) ;
contentPathArray = contentHash [ " path " ] . toUtf8 ( ) ;
contentLabelArray = contentHash [ " label_noext " ] . toUtf8 ( ) ;
break ;
}
}
break ;
}
default :
return ;
}
corePath = corePathArray . constData ( ) ;
contentPath = contentPathArray . constData ( ) ;
contentLabel = contentLabelArray . constData ( ) ;
content_info . argc = 0 ;
content_info . argv = NULL ;
content_info . args = NULL ;
content_info . environ_get = NULL ;
2019-01-06 22:03:16 -05:00
# ifdef HAVE_MENU
2018-04-30 20:33:28 -04:00
menu_navigation_set_selection ( 0 ) ;
2019-01-06 22:03:16 -05:00
# endif
2018-04-30 20:33:28 -04:00
command_event ( CMD_EVENT_UNLOAD_CORE , NULL ) ;
2019-01-06 22:03:16 -05:00
if ( ! task_push_load_content_with_new_core_from_companion_ui (
2019-01-12 00:51:44 +01:00
corePath , contentPath , contentLabel , & content_info ,
2019-01-06 22:03:16 -05:00
NULL , NULL ) )
2018-04-30 14:33:05 -04:00
{
QMessageBox : : critical ( this , msg_hash_to_str ( MSG_ERROR ) , msg_hash_to_str ( MSG_FAILED_TO_LOAD_CONTENT ) ) ;
return ;
}
2019-01-06 22:03:16 -05:00
# ifdef HAVE_MENU
2018-04-30 14:33:05 -04:00
menu_driver_ctl ( RARCH_MENU_CTL_SET_PENDING_QUICK_MENU , NULL ) ;
# endif
}
2018-07-23 11:17:58 -04:00
void MainWindow : : onRunClicked ( )
{
2019-01-07 20:56:23 +01:00
QHash < QString , QString > contentHash ;
2019-02-03 15:49:35 -08:00
2019-01-07 20:56:23 +01:00
switch ( m_currentBrowser )
{
2019-01-07 21:24:44 +01:00
case BROWSER_TYPE_FILES :
contentHash = getFileContentHash ( m_proxyFileModel - > mapToSource ( m_fileTableView - > currentIndex ( ) ) ) ;
break ;
case BROWSER_TYPE_PLAYLISTS :
contentHash = getCurrentContentHash ( ) ;
break ;
2019-01-07 20:56:23 +01:00
}
2019-02-03 15:49:35 -08:00
2018-12-12 20:45:19 +01:00
if ( contentHash . isEmpty ( ) )
2018-07-28 11:48:24 -04:00
return ;
2019-02-03 15:49:35 -08:00
2018-07-23 11:17:58 -04:00
loadContent ( contentHash ) ;
}
2018-04-30 14:33:05 -04:00
bool MainWindow : : isContentLessCore ( )
{
rarch_system_info_t * system = runloop_get_system_info ( ) ;
return system - > load_no_content ;
}
bool MainWindow : : isCoreLoaded ( )
{
if ( m_currentCore . isEmpty ( ) | | m_currentCore = = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_NO_CORE ) )
return false ;
return true ;
}
2018-07-27 23:45:48 -04:00
PlaylistEntryDialog * MainWindow : : playlistEntryDialog ( )
{
return m_playlistEntryDialog ;
}
2018-04-30 14:33:05 -04:00
ViewOptionsDialog * MainWindow : : viewOptionsDialog ( )
{
return m_viewOptionsDialog ;
}
void MainWindow : : setCoreActions ( )
{
QListWidgetItem * currentPlaylistItem = m_listWidget - > currentItem ( ) ;
2018-07-23 11:17:58 -04:00
ViewType viewType = getCurrentViewType ( ) ;
2018-12-12 20:45:19 +01:00
QHash < QString , QString > hash = getCurrentContentHash ( ) ;
2019-01-10 01:01:01 +01:00
QString currentPlaylistFileName = QString ( ) ;
2018-04-30 14:33:05 -04:00
m_launchWithComboBox - > clear ( ) ;
if ( isContentLessCore ( ) )
m_startCorePushButton - > show ( ) ;
else
m_startCorePushButton - > hide ( ) ;
2018-04-30 20:33:28 -04:00
if ( isCoreLoaded ( ) & & m_settings - > value ( " suggest_loaded_core_first " , false ) . toBool ( ) )
2018-04-30 14:33:05 -04:00
{
QVariantMap comboBoxMap ;
comboBoxMap [ " core_name " ] = m_currentCore ;
comboBoxMap [ " core_path " ] = path_get ( RARCH_PATH_CORE ) ;
comboBoxMap [ " core_selection " ] = CORE_SELECTION_CURRENT ;
m_launchWithComboBox - > addItem ( m_currentCore , QVariant : : fromValue ( comboBoxMap ) ) ;
}
2019-01-07 20:56:23 +01:00
if ( m_currentBrowser = = BROWSER_TYPE_PLAYLISTS )
2018-04-30 14:33:05 -04:00
{
2018-07-24 17:07:17 -04:00
if ( ! hash . isEmpty ( ) )
2018-04-30 14:33:05 -04:00
{
QString coreName = hash [ " core_name " ] ;
if ( coreName . isEmpty ( ) )
{
coreName = " <n/a> " ;
}
else
{
const char * detect_str = file_path_str ( FILE_PATH_DETECT ) ;
if ( coreName ! = detect_str )
{
if ( m_launchWithComboBox - > findText ( coreName ) = = - 1 )
{
int i = 0 ;
bool found_existing = false ;
for ( i = 0 ; i < m_launchWithComboBox - > count ( ) ; i + + )
{
QVariantMap map = m_launchWithComboBox - > itemData ( i , Qt : : UserRole ) . toMap ( ) ;
if ( map . value ( " core_path " ) . toString ( ) = = hash [ " core_path " ] | | map . value ( " core_name " ) . toString ( ) = = coreName )
{
found_existing = true ;
break ;
}
}
if ( ! found_existing )
{
QVariantMap comboBoxMap ;
comboBoxMap [ " core_name " ] = coreName ;
comboBoxMap [ " core_path " ] = hash [ " core_path " ] ;
comboBoxMap [ " core_selection " ] = CORE_SELECTION_PLAYLIST_SAVED ;
m_launchWithComboBox - > addItem ( coreName , QVariant : : fromValue ( comboBoxMap ) ) ;
}
}
}
}
}
}
2019-01-10 01:01:01 +01:00
switch ( m_currentBrowser )
{
case BROWSER_TYPE_PLAYLISTS :
currentPlaylistFileName = hash [ " db_name " ] ;
break ;
case BROWSER_TYPE_FILES :
currentPlaylistFileName = m_fileModel - > rootDirectory ( ) . dirName ( ) ;
break ;
2019-01-07 23:50:21 +01:00
}
2019-01-10 01:01:01 +01:00
if ( ! currentPlaylistFileName . isEmpty ( ) )
2018-04-30 14:33:05 -04:00
{
2018-05-06 01:36:47 -04:00
QVector < QHash < QString , QString > > defaultCores = getPlaylistDefaultCores ( ) ;
2018-04-30 14:33:05 -04:00
int i = 0 ;
if ( defaultCores . count ( ) > 0 )
{
QString currentPlaylistItemDataString ;
bool allPlaylists = false ;
int row = 0 ;
if ( currentPlaylistItem )
{
currentPlaylistItemDataString = currentPlaylistItem - > data ( Qt : : UserRole ) . toString ( ) ;
allPlaylists = ( currentPlaylistItemDataString = = ALL_PLAYLISTS_TOKEN ) ;
}
for ( row = 0 ; row < m_listWidget - > count ( ) ; row + + )
{
if ( allPlaylists )
{
QListWidgetItem * listItem = m_listWidget - > item ( row ) ;
QString listItemString = listItem - > data ( Qt : : UserRole ) . toString ( ) ;
QFileInfo info ;
info . setFile ( listItemString ) ;
if ( listItemString = = ALL_PLAYLISTS_TOKEN )
continue ;
}
for ( i = 0 ; i < defaultCores . count ( ) ; i + + )
{
QString playlist = defaultCores . at ( i ) [ " playlist_filename " ] ;
QString core = defaultCores . at ( i ) [ " core_path " ] ;
playlist . remove ( file_path_str ( FILE_PATH_LPL_EXTENSION ) ) ;
if ( currentPlaylistFileName = = playlist )
{
core_info_list_t * coreInfoList = NULL ;
unsigned j = 0 ;
core_info_get_list ( & coreInfoList ) ;
2019-01-06 17:45:22 -05:00
if ( coreInfoList )
2018-04-30 14:33:05 -04:00
{
2019-01-06 17:45:22 -05:00
for ( j = 0 ; j < coreInfoList - > count ; j + + )
2018-04-30 14:33:05 -04:00
{
2019-01-06 17:45:22 -05:00
const core_info_t * info = & coreInfoList - > list [ j ] ;
2018-04-30 14:33:05 -04:00
2019-01-06 17:45:22 -05:00
if ( core = = info - > path )
{
if ( m_launchWithComboBox - > findText ( info - > core_name ) = = - 1 )
2018-04-30 14:33:05 -04:00
{
2019-01-06 17:45:22 -05:00
int i = 0 ;
bool found_existing = false ;
2018-04-30 14:33:05 -04:00
2019-01-06 17:45:22 -05:00
for ( i = 0 ; i < m_launchWithComboBox - > count ( ) ; i + + )
2018-04-30 14:33:05 -04:00
{
2019-01-06 17:45:22 -05:00
QVariantMap map = m_launchWithComboBox - > itemData ( i , Qt : : UserRole ) . toMap ( ) ;
if ( map . value ( " core_path " ) . toString ( ) = = info - > path | | map . value ( " core_name " ) . toString ( ) = = info - > core_name )
{
found_existing = true ;
break ;
}
2018-04-30 14:33:05 -04:00
}
2019-01-06 17:45:22 -05:00
if ( ! found_existing )
{
QVariantMap comboBoxMap ;
comboBoxMap [ " core_name " ] = info - > core_name ;
comboBoxMap [ " core_path " ] = info - > path ;
comboBoxMap [ " core_selection " ] = CORE_SELECTION_PLAYLIST_DEFAULT ;
m_launchWithComboBox - > addItem ( info - > core_name , QVariant : : fromValue ( comboBoxMap ) ) ;
}
2018-04-30 14:33:05 -04:00
}
}
}
}
}
}
if ( ! allPlaylists )
break ;
}
}
}
{
QVariantMap comboBoxMap ;
comboBoxMap [ " core_selection " ] = CORE_SELECTION_ASK ;
m_launchWithComboBox - > addItem ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_CORE_SELECTION_ASK ) , QVariant : : fromValue ( comboBoxMap ) ) ;
m_launchWithComboBox - > insertSeparator ( m_launchWithComboBox - > count ( ) ) ;
comboBoxMap [ " core_selection " ] = CORE_SELECTION_LOAD_CORE ;
m_launchWithComboBox - > addItem ( QString ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_LOAD_CORE ) ) + " ... " , QVariant : : fromValue ( comboBoxMap ) ) ;
}
}
void MainWindow : : onTabWidgetIndexChanged ( int index )
{
2019-01-07 20:56:23 +01:00
if ( m_browserAndPlaylistTabWidget - > tabText ( index ) = = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_TAB_FILE_BROWSER ) )
2018-04-30 14:33:05 -04:00
{
2019-01-07 20:56:23 +01:00
m_currentBrowser = BROWSER_TYPE_FILES ;
2018-04-30 14:33:05 -04:00
2019-01-07 20:56:23 +01:00
m_centralWidget - > setCurrentWidget ( m_fileTableView ) ;
2018-07-23 11:17:58 -04:00
2019-01-07 20:56:23 +01:00
onCurrentFileChanged ( m_fileTableView - > currentIndex ( ) ) ;
2018-04-30 14:33:05 -04:00
}
2019-01-07 20:56:23 +01:00
else if ( m_browserAndPlaylistTabWidget - > tabText ( index ) = = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_TAB_PLAYLISTS ) )
2018-04-30 14:33:05 -04:00
{
2019-01-07 20:56:23 +01:00
m_currentBrowser = BROWSER_TYPE_PLAYLISTS ;
2018-04-30 14:33:05 -04:00
2019-01-13 23:34:47 +01:00
m_centralWidget - > setCurrentWidget ( m_playlistViewsAndFooter ) ;
2018-07-23 11:17:58 -04:00
2019-01-07 20:56:23 +01:00
onCurrentItemChanged ( m_tableView - > currentIndex ( ) ) ;
2018-04-30 14:33:05 -04:00
}
2019-01-07 20:56:23 +01:00
applySearch ( ) ;
2018-04-30 14:33:05 -04:00
setCoreActions ( ) ;
}
QToolButton * MainWindow : : runPushButton ( )
{
return m_runPushButton ;
}
QToolButton * MainWindow : : stopPushButton ( )
{
return m_stopPushButton ;
}
QToolButton * MainWindow : : startCorePushButton ( )
{
return m_startCorePushButton ;
}
QComboBox * MainWindow : : launchWithComboBox ( )
{
return m_launchWithComboBox ;
}
void MainWindow : : onSearchLineEditEdited ( const QString & text )
{
int i = 0 ;
QVector < unsigned > textUnicode = text . toUcs4 ( ) ;
QVector < unsigned > textHiraToKata ;
QVector < unsigned > textKataToHira ;
bool foundHira = false ;
bool foundKata = false ;
for ( i = 0 ; i < textUnicode . size ( ) ; i + + )
{
unsigned code = textUnicode . at ( i ) ;
if ( code > = HIRAGANA_START & & code < = HIRAGANA_END )
{
foundHira = true ;
textHiraToKata + = code + HIRA_KATA_OFFSET ;
}
else if ( code > = KATAKANA_START & & code < = KATAKANA_END )
{
foundKata = true ;
textKataToHira + = code - HIRA_KATA_OFFSET ;
}
else
{
textHiraToKata + = code ;
textKataToHira + = code ;
}
}
2018-12-12 20:45:19 +01:00
if ( ! foundHira & & ! foundKata )
2018-04-30 14:33:05 -04:00
{
2019-01-07 20:56:23 +01:00
m_searchRegExp = QRegExp ( text , Qt : : CaseInsensitive ) ;
2018-12-12 20:45:19 +01:00
}
else if ( foundHira & & ! foundKata )
{
2019-01-07 20:56:23 +01:00
m_searchRegExp = QRegExp ( text + " | " + QString : : fromUcs4 ( textHiraToKata . constData ( ) , textHiraToKata . size ( ) ) , Qt : : CaseInsensitive ) ;
2018-12-12 20:45:19 +01:00
}
else if ( ! foundHira & & foundKata )
{
2019-01-07 20:56:23 +01:00
m_searchRegExp = QRegExp ( text + " | " + QString : : fromUcs4 ( textKataToHira . constData ( ) , textKataToHira . size ( ) ) , Qt : : CaseInsensitive ) ;
2018-12-12 20:45:19 +01:00
}
else
{
2019-01-07 20:56:23 +01:00
m_searchRegExp = QRegExp ( text + " | " + QString : : fromUcs4 ( textHiraToKata . constData ( ) , textHiraToKata . size ( ) ) + " | " + QString : : fromUcs4 ( textKataToHira . constData ( ) , textKataToHira . size ( ) ) , Qt : : CaseInsensitive ) ;
}
applySearch ( ) ;
}
void MainWindow : : applySearch ( )
{
switch ( m_currentBrowser )
{
case BROWSER_TYPE_PLAYLISTS :
if ( m_proxyModel - > filterRegExp ( ) ! = m_searchRegExp )
{
m_proxyModel - > setFilterRegExp ( m_searchRegExp ) ;
updateItemsCount ( ) ;
}
break ;
case BROWSER_TYPE_FILES :
if ( m_proxyFileModel - > filterRegExp ( ) ! = m_searchRegExp )
{
m_proxyFileModel - > setFilterRegExp ( m_searchRegExp ) ;
}
break ;
2018-04-30 14:33:05 -04:00
}
}
void MainWindow : : onViewClosedDocksAboutToShow ( )
{
QMenu * menu = qobject_cast < QMenu * > ( sender ( ) ) ;
QList < QDockWidget * > dockWidgets ;
bool found = false ;
2018-05-06 01:36:47 -04:00
int i = 0 ;
2018-04-30 14:33:05 -04:00
if ( ! menu )
return ;
dockWidgets = findChildren < QDockWidget * > ( ) ;
menu - > clear ( ) ;
if ( dockWidgets . isEmpty ( ) )
{
menu - > addAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_NONE ) ) ;
return ;
}
2018-07-26 23:34:29 -04:00
for ( i = 0 ; i < dockWidgets . count ( ) ; i + + )
2018-04-30 14:33:05 -04:00
{
2018-05-06 01:36:47 -04:00
const QDockWidget * dock = dockWidgets . at ( i ) ;
2018-04-30 14:33:05 -04:00
if ( ! dock - > isVisible ( ) )
{
QAction * action = menu - > addAction ( dock - > property ( " menu_text " ) . toString ( ) , this , SLOT ( onShowHiddenDockWidgetAction ( ) ) ) ;
action - > setProperty ( " dock_name " , dock - > objectName ( ) ) ;
found = true ;
}
}
if ( ! found )
menu - > addAction ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_NONE ) ) ;
}
void MainWindow : : onShowHiddenDockWidgetAction ( )
{
QAction * action = qobject_cast < QAction * > ( sender ( ) ) ;
QDockWidget * dock = NULL ;
if ( ! action )
return ;
dock = findChild < QDockWidget * > ( action - > property ( " dock_name " ) . toString ( ) ) ;
if ( ! dock )
return ;
if ( ! dock - > isVisible ( ) )
{
addDockWidget ( static_cast < Qt : : DockWidgetArea > ( dock - > property ( " default_area " ) . toInt ( ) ) , dock ) ;
dock - > setVisible ( true ) ;
dock - > setFloating ( false ) ;
}
}
QWidget * MainWindow : : searchWidget ( )
{
return m_searchWidget ;
}
QLineEdit * MainWindow : : searchLineEdit ( )
{
return m_searchLineEdit ;
}
void MainWindow : : onSearchEnterPressed ( )
{
onSearchLineEditEdited ( m_searchLineEdit - > text ( ) ) ;
}
2018-12-12 20:45:19 +01:00
void MainWindow : : onCurrentTableItemDataChanged ( const QModelIndex & topLeft , const QModelIndex & bottomRight , const QVector < int > & roles )
2018-04-30 14:33:05 -04:00
{
2018-12-16 01:20:11 +01:00
QHash < QString , QString > hash ;
2018-12-12 20:45:19 +01:00
if ( ! roles . contains ( Qt : : EditRole ) )
2018-04-30 14:33:05 -04:00
return ;
2018-12-12 20:45:19 +01:00
if ( topLeft ! = bottomRight )
2018-09-16 21:34:28 -04:00
return ;
2018-12-16 01:20:11 +01:00
hash = topLeft . data ( PlaylistModel : : HASH ) . value < QHash < QString , QString > > ( ) ;
2018-09-16 21:34:28 -04:00
updateCurrentPlaylistEntry ( hash ) ;
2019-01-07 20:56:23 +01:00
onCurrentItemChanged ( topLeft ) ;
2018-09-16 21:34:28 -04:00
}
2018-09-18 14:09:25 -04:00
void MainWindow : : onCurrentListItemDataChanged ( QListWidgetItem * item )
{
renamePlaylistItem ( item , item - > text ( ) ) ;
}
void MainWindow : : renamePlaylistItem ( QListWidgetItem * item , QString newName )
{
QString oldPath ;
QString newPath ;
QString extension ;
QString oldName ;
QFile file ;
QFileInfo info ;
QFileInfo playlistInfo ;
QString playlistPath ;
settings_t * settings = config_get_ptr ( ) ;
QDir playlistDir ( settings - > paths . directory_playlist ) ;
bool specialPlaylist = false ;
if ( ! item )
return ;
playlistPath = item - > data ( Qt : : UserRole ) . toString ( ) ;
playlistInfo = playlistPath ;
oldName = playlistInfo . completeBaseName ( ) ;
/* Don't just compare strings in case there are case differences on Windows that should be ignored. */
if ( QDir ( playlistInfo . absoluteDir ( ) ) ! = QDir ( playlistDir ) )
{
/* special playlists like history etc. can't have an association */
specialPlaylist = true ;
}
if ( specialPlaylist )
{
/* special playlists shouldn't be editable already, but just in case, set the old name back and early return if they rename it */
item - > setText ( oldName ) ;
return ;
}
/* block this signal because setData() would trigger an infinite loop here */
disconnect ( m_listWidget , SIGNAL ( itemChanged ( QListWidgetItem * ) ) , this , SLOT ( onCurrentListItemDataChanged ( QListWidgetItem * ) ) ) ;
oldPath = item - > data ( Qt : : UserRole ) . toString ( ) ;
file . setFileName ( oldPath ) ;
info = file ;
extension = info . suffix ( ) ;
newPath = info . absolutePath ( ) ;
/* absolutePath() will always use / even on Windows */
if ( newPath . at ( newPath . count ( ) - 1 ) ! = ' / ' )
{
/* add trailing slash if the path doesn't have one */
newPath + = ' / ' ;
}
newPath + = newName + " . " + extension ;
item - > setData ( Qt : : UserRole , newPath ) ;
if ( ! file . rename ( newPath ) )
{
RARCH_ERR ( " [Qt]: Could not rename playlist. \n " ) ;
item - > setText ( oldName ) ;
}
connect ( m_listWidget , SIGNAL ( itemChanged ( QListWidgetItem * ) ) , this , SLOT ( onCurrentListItemDataChanged ( QListWidgetItem * ) ) ) ;
}
2019-01-07 20:56:23 +01:00
void MainWindow : : onCurrentItemChanged ( const QModelIndex & index )
{
onCurrentItemChanged ( index . data ( PlaylistModel : : HASH ) . value < QHash < QString , QString > > ( ) ) ;
}
void MainWindow : : onCurrentFileChanged ( const QModelIndex & index )
{
onCurrentItemChanged ( getFileContentHash ( m_proxyFileModel - > mapToSource ( index ) ) ) ;
}
void MainWindow : : onCurrentItemChanged ( const QHash < QString , QString > & hash )
2018-07-23 11:17:58 -04:00
{
2019-01-23 21:21:30 +01:00
QString path = hash [ " path " ] ;
2019-01-30 21:26:33 +01:00
bool acceptDrop = false ;
2018-04-30 14:33:05 -04:00
if ( m_thumbnailPixmap )
delete m_thumbnailPixmap ;
if ( m_thumbnailPixmap2 )
delete m_thumbnailPixmap2 ;
if ( m_thumbnailPixmap3 )
delete m_thumbnailPixmap3 ;
2019-01-23 21:21:30 +01:00
if ( m_playlistModel - > isSupportedImage ( path ) )
2018-04-30 14:33:05 -04:00
{
/* use thumbnail widgets to show regular image files */
2019-01-23 21:21:30 +01:00
m_thumbnailPixmap = new QPixmap ( path ) ;
2018-04-30 14:33:05 -04:00
m_thumbnailPixmap2 = new QPixmap ( * m_thumbnailPixmap ) ;
m_thumbnailPixmap3 = new QPixmap ( * m_thumbnailPixmap ) ;
}
else
{
2019-01-23 21:21:30 +01:00
QString thumbnailsDir = m_playlistModel - > getPlaylistThumbnailsDir ( hash [ " db_name " ] ) ;
QString thumbnailName = m_playlistModel - > getSanitizedThumbnailName ( hash [ " label_noext " ] ) ;
m_thumbnailPixmap = new QPixmap ( thumbnailsDir + " / " + THUMBNAIL_BOXART + " / " + thumbnailName ) ;
m_thumbnailPixmap2 = new QPixmap ( thumbnailsDir + " / " + THUMBNAIL_TITLE + " / " + thumbnailName ) ;
m_thumbnailPixmap3 = new QPixmap ( thumbnailsDir + " / " + THUMBNAIL_SCREENSHOT + " / " + thumbnailName ) ;
2019-01-23 19:28:59 +01:00
2019-01-30 21:26:33 +01:00
if ( m_currentBrowser = = BROWSER_TYPE_PLAYLISTS & & ! currentPlaylistIsSpecial ( ) )
acceptDrop = true ;
2018-04-30 14:33:05 -04:00
}
2019-01-30 21:26:33 +01:00
onResizeThumbnailOne ( * m_thumbnailPixmap , acceptDrop ) ;
onResizeThumbnailTwo ( * m_thumbnailPixmap2 , acceptDrop ) ;
onResizeThumbnailThree ( * m_thumbnailPixmap3 , acceptDrop ) ;
2018-04-30 14:33:05 -04:00
setCoreActions ( ) ;
}
2019-01-30 21:26:33 +01:00
void MainWindow : : setThumbnail ( QString widgetName , QPixmap & pixmap , bool acceptDrop )
2018-04-30 14:33:05 -04:00
{
2019-01-30 21:26:33 +01:00
ThumbnailWidget * thumbnail = findChild < ThumbnailWidget * > ( widgetName ) ;
if ( thumbnail )
thumbnail - > setPixmap ( pixmap , acceptDrop ) ;
2018-04-30 14:33:05 -04:00
}
2019-01-30 21:26:33 +01:00
void MainWindow : : onResizeThumbnailOne ( QPixmap & pixmap , bool acceptDrop )
2018-04-30 14:33:05 -04:00
{
2019-01-30 21:26:33 +01:00
setThumbnail ( " thumbnail " , pixmap , acceptDrop ) ;
2018-04-30 14:33:05 -04:00
}
2019-01-30 21:26:33 +01:00
void MainWindow : : onResizeThumbnailTwo ( QPixmap & pixmap , bool acceptDrop )
2018-04-30 14:33:05 -04:00
{
2019-01-30 21:26:33 +01:00
setThumbnail ( " thumbnail2 " , pixmap , acceptDrop ) ;
2018-04-30 14:33:05 -04:00
}
2019-01-30 21:26:33 +01:00
void MainWindow : : onResizeThumbnailThree ( QPixmap & pixmap , bool acceptDrop )
2018-04-30 14:33:05 -04:00
{
2019-01-30 21:26:33 +01:00
setThumbnail ( " thumbnail3 " , pixmap , acceptDrop ) ;
2018-04-30 14:33:05 -04:00
}
2018-05-07 02:36:00 -04:00
void MainWindow : : setCurrentViewType ( ViewType viewType )
{
m_viewType = viewType ;
switch ( viewType )
{
case VIEW_TYPE_ICONS :
{
2019-01-13 23:34:47 +01:00
m_playlistViews - > setCurrentWidget ( m_gridView ) ;
2019-01-07 20:56:23 +01:00
m_zoomWidget - > show ( ) ;
2018-05-07 02:36:00 -04:00
break ;
}
case VIEW_TYPE_LIST :
default :
{
2019-01-13 23:34:47 +01:00
m_playlistViews - > setCurrentWidget ( m_tableView ) ;
2019-01-07 20:56:23 +01:00
m_zoomWidget - > hide ( ) ;
2018-05-07 02:36:00 -04:00
break ;
}
}
}
2018-12-12 20:45:19 +01:00
void MainWindow : : setCurrentThumbnailType ( ThumbnailType thumbnailType )
{
m_thumbnailType = thumbnailType ;
m_playlistModel - > setThumbnailType ( thumbnailType ) ;
updateVisibleItems ( ) ;
m_gridView - > viewport ( ) - > update ( ) ;
}
2018-05-07 02:36:00 -04:00
MainWindow : : ViewType MainWindow : : getCurrentViewType ( )
{
return m_viewType ;
}
2018-12-12 20:45:19 +01:00
ThumbnailType MainWindow : : getCurrentThumbnailType ( )
2018-04-30 14:33:05 -04:00
{
2018-12-12 20:45:19 +01:00
return m_thumbnailType ;
}
2018-05-07 02:36:00 -04:00
2018-12-12 20:45:19 +01:00
void MainWindow : : onCurrentListItemChanged ( QListWidgetItem * current , QListWidgetItem * previous )
{
2018-04-30 14:33:05 -04:00
Q_UNUSED ( current )
Q_UNUSED ( previous )
2018-12-12 20:45:19 +01:00
initContentTableWidget ( ) ;
2018-05-07 02:36:00 -04:00
2018-04-30 14:33:05 -04:00
setCoreActions ( ) ;
}
2018-12-12 20:45:19 +01:00
TableView * MainWindow : : contentTableView ( )
2018-04-30 14:33:05 -04:00
{
2018-12-12 20:45:19 +01:00
return m_tableView ;
2018-04-30 14:33:05 -04:00
}
2019-01-07 20:56:23 +01:00
QTableView * MainWindow : : fileTableView ( )
2018-05-02 23:04:10 -04:00
{
2019-01-07 20:56:23 +01:00
return m_fileTableView ;
}
QStackedWidget * MainWindow : : centralWidget ( )
{
return m_centralWidget ;
}
FileDropWidget * MainWindow : : playlistViews ( )
{
return m_playlistViews ;
}
2019-01-13 23:34:47 +01:00
QWidget * MainWindow : : playlistViewsAndFooter ( )
2018-05-02 23:04:10 -04:00
{
2019-01-13 23:34:47 +01:00
return m_playlistViewsAndFooter ;
2018-05-02 23:04:10 -04:00
}
2018-12-12 20:45:19 +01:00
GridView * MainWindow : : contentGridView ( )
2018-05-02 23:04:10 -04:00
{
2018-12-12 20:45:19 +01:00
return m_gridView ;
2018-05-02 23:04:10 -04:00
}
2018-04-30 14:33:05 -04:00
void MainWindow : : onBrowserDownloadsClicked ( )
{
settings_t * settings = config_get_ptr ( ) ;
QDir dir ( settings - > paths . directory_core_assets ) ;
2018-09-01 21:24:59 -04:00
QString path = dir . absolutePath ( ) ;
QModelIndex index ;
2018-04-30 14:33:05 -04:00
2018-09-01 21:24:59 -04:00
m_pendingDirScrollPath = path ;
index = m_dirModel - > index ( path ) ;
m_dirTree - > setCurrentIndex ( index ) ;
onDownloadScroll ( path ) ;
}
void MainWindow : : onDownloadScroll ( QString path )
{
QModelIndex index = m_dirModel - > index ( path ) ;
m_dirTree - > scrollTo ( index , QAbstractItemView : : PositionAtTop ) ;
m_dirTree - > expand ( index ) ;
/* FIXME: Find a way to make this unnecessary */
emit scrollToDownloadsAgain ( path ) ;
}
void MainWindow : : onDownloadScrollAgain ( QString path )
{
QModelIndex index = m_dirModel - > index ( path ) ;
m_dirTree - > scrollTo ( index , QAbstractItemView : : PositionAtTop ) ;
m_dirTree - > expand ( index ) ;
2018-04-30 14:33:05 -04:00
}
void MainWindow : : onBrowserUpClicked ( )
{
QDir dir ( m_dirModel - > filePath ( m_dirTree - > currentIndex ( ) ) ) ;
dir . cdUp ( ) ;
m_dirTree - > setCurrentIndex ( m_dirModel - > index ( dir . absolutePath ( ) ) ) ;
m_dirTree - > scrollTo ( m_dirTree - > currentIndex ( ) , QAbstractItemView : : EnsureVisible ) ;
}
void MainWindow : : onBrowserStartClicked ( )
{
settings_t * settings = config_get_ptr ( ) ;
m_dirTree - > setCurrentIndex ( m_dirModel - > index ( settings - > paths . directory_menu_content ) ) ;
m_dirTree - > scrollTo ( m_dirTree - > currentIndex ( ) , QAbstractItemView : : PositionAtTop ) ;
}
2018-09-18 14:09:25 -04:00
ListWidget * MainWindow : : playlistListWidget ( )
2018-04-30 14:33:05 -04:00
{
return m_listWidget ;
}
TreeView * MainWindow : : dirTreeView ( )
{
return m_dirTree ;
}
void MainWindow : : onTimeout ( )
{
bool contentless = false ;
bool is_inited = false ;
content_get_status ( & contentless , & is_inited ) ;
if ( is_inited )
{
if ( m_runPushButton - > isVisible ( ) )
m_runPushButton - > hide ( ) ;
if ( ! m_stopPushButton - > isVisible ( ) )
m_stopPushButton - > show ( ) ;
}
else
{
if ( ! m_runPushButton - > isVisible ( ) )
m_runPushButton - > show ( ) ;
if ( m_stopPushButton - > isVisible ( ) )
m_stopPushButton - > hide ( ) ;
}
setCurrentCoreLabel ( ) ;
}
void MainWindow : : onStopClicked ( )
{
2019-01-06 17:37:36 -05:00
# ifdef HAVE_MENU
2018-04-30 14:33:05 -04:00
menu_navigation_set_selection ( 0 ) ;
2019-01-06 17:37:36 -05:00
# endif
2018-04-30 14:33:05 -04:00
command_event ( CMD_EVENT_UNLOAD_CORE , NULL ) ;
setCurrentCoreLabel ( ) ;
2018-04-30 19:52:12 -04:00
activateWindow ( ) ;
raise ( ) ;
2018-04-30 14:33:05 -04:00
}
void MainWindow : : setCurrentCoreLabel ( )
{
2018-10-30 17:11:07 +01:00
bool update = false ;
struct retro_system_info * system = runloop_get_libretro_system_info ( ) ;
QString libraryName = system - > library_name ;
const char * no_core_str = msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_NO_CORE ) ;
2018-04-30 14:33:05 -04:00
if ( m_statusLabel - > text ( ) . isEmpty ( ) | | ( m_currentCore ! = no_core_str & & libraryName . isEmpty ( ) ) )
{
m_currentCore = no_core_str ;
m_currentCoreVersion = " " ;
update = true ;
}
else
{
if ( m_currentCore ! = libraryName & & ! libraryName . isEmpty ( ) )
{
2018-10-30 17:11:07 +01:00
m_currentCore = system - > library_name ;
m_currentCoreVersion = ( string_is_empty ( system - > library_version ) ? " " : system - > library_version ) ;
2018-04-30 14:33:05 -04:00
update = true ;
}
}
if ( update )
{
QAction * unloadCoreAction = findChild < QAction * > ( " unloadCoreAction " ) ;
QString text = QString ( PACKAGE_VERSION ) + " - " + m_currentCore + " " + m_currentCoreVersion ;
m_statusLabel - > setText ( text ) ;
m_loadCoreWindow - > setStatusLabel ( text ) ;
setCoreActions ( ) ;
if ( unloadCoreAction )
{
if ( libraryName . isEmpty ( ) )
unloadCoreAction - > setEnabled ( false ) ;
else
unloadCoreAction - > setEnabled ( true ) ;
}
}
}
void MainWindow : : onCoreLoadWindowClosed ( )
{
QVariant lastLaunchWithVariant = m_loadCoreWindow - > property ( " last_launch_with_index " ) ;
int lastLaunchWithIndex = lastLaunchWithVariant . toInt ( ) ;
m_pendingRun = false ;
if ( lastLaunchWithVariant . isValid ( ) & & lastLaunchWithIndex > = 0 )
{
m_launchWithComboBox - > setCurrentIndex ( lastLaunchWithIndex ) ;
m_loadCoreWindow - > setProperty ( " last_launch_with_index " , - 1 ) ;
}
}
void MainWindow : : onCoreLoaded ( )
{
QAction * unloadAction = findChild < QAction * > ( " unloadCoreAction " ) ;
activateWindow ( ) ;
raise ( ) ;
setCurrentCoreLabel ( ) ;
setCoreActions ( ) ;
if ( unloadAction )
unloadAction - > setEnabled ( true ) ;
m_loadCoreWindow - > hide ( ) ;
if ( m_pendingRun )
{
onRunClicked ( ) ;
2018-04-30 20:33:28 -04:00
m_pendingRun = false ;
2018-04-30 14:33:05 -04:00
}
}
void MainWindow : : onUnloadCoreMenuAction ( )
{
QAction * action = qobject_cast < QAction * > ( sender ( ) ) ;
2019-01-06 17:37:36 -05:00
# ifdef HAVE_MENU
2018-04-30 14:33:05 -04:00
menu_navigation_set_selection ( 0 ) ;
2019-01-06 17:37:36 -05:00
# endif
2018-04-30 14:33:05 -04:00
if ( ! command_event ( CMD_EVENT_UNLOAD_CORE , NULL ) )
{
/* TODO */
return ;
}
setCurrentCoreLabel ( ) ;
setCoreActions ( ) ;
if ( ! action )
return ;
action - > setEnabled ( false ) ;
2018-04-30 19:52:12 -04:00
activateWindow ( ) ;
raise ( ) ;
2018-04-30 14:33:05 -04:00
}
void MainWindow : : onLoadCoreClicked ( const QStringList & extensionFilters )
{
m_loadCoreWindow - > show ( ) ;
m_loadCoreWindow - > resize ( width ( ) / 2 , height ( ) ) ;
m_loadCoreWindow - > setGeometry ( QStyle : : alignedRect ( Qt : : LeftToRight , Qt : : AlignCenter , m_loadCoreWindow - > size ( ) , geometry ( ) ) ) ;
m_loadCoreWindow - > initCoreList ( extensionFilters ) ;
}
void MainWindow : : initContentTableWidget ( )
{
QListWidgetItem * item = m_listWidget - > currentItem ( ) ;
QString path ;
2018-05-02 01:16:09 -04:00
int i = 0 ;
2018-04-30 14:33:05 -04:00
if ( ! item )
return ;
2018-07-24 17:07:17 -04:00
m_currentGridHash . clear ( ) ;
2018-07-25 00:29:48 -04:00
if ( m_currentGridWidget )
{
m_currentGridWidget - > setObjectName ( " thumbnailWidget " ) ;
2018-07-25 01:43:57 -04:00
m_currentGridWidget - > style ( ) - > unpolish ( m_currentGridWidget ) ;
m_currentGridWidget - > style ( ) - > polish ( m_currentGridWidget ) ;
2018-07-25 00:29:48 -04:00
}
m_currentGridWidget = NULL ;
2018-04-30 14:33:05 -04:00
path = item - > data ( Qt : : UserRole ) . toString ( ) ;
if ( path = = ALL_PLAYLISTS_TOKEN )
{
settings_t * settings = config_get_ptr ( ) ;
QDir playlistDir ( settings - > paths . directory_playlist ) ;
2018-07-24 15:09:18 -04:00
QStringList playlists ;
2018-05-06 01:36:47 -04:00
int i = 0 ;
2018-04-30 14:33:05 -04:00
2018-07-26 23:34:29 -04:00
for ( i = 0 ; i < m_playlistFiles . count ( ) ; i + + )
2018-04-30 14:33:05 -04:00
{
2018-05-06 01:36:47 -04:00
const QString & playlist = m_playlistFiles . at ( i ) ;
2018-07-24 15:09:18 -04:00
playlists . append ( playlistDir . absoluteFilePath ( playlist ) ) ;
2018-04-30 14:33:05 -04:00
}
2018-07-24 15:09:18 -04:00
2018-12-12 20:45:19 +01:00
m_playlistModel - > addPlaylistItems ( playlists , true ) ;
2018-04-30 14:33:05 -04:00
}
else
2018-12-12 20:45:19 +01:00
m_playlistModel - > addPlaylistItems ( QStringList ( ) < < path ) ;
2018-04-30 14:33:05 -04:00
if ( item ! = m_historyPlaylistsItem )
2018-12-12 20:45:19 +01:00
m_tableView - > sortByColumn ( 0 , Qt : : AscendingOrder ) ;
2018-12-16 01:20:11 +01:00
else
m_proxyModel - > sort ( - 1 ) ;
2018-04-30 14:33:05 -04:00
2019-01-07 20:56:23 +01:00
updateItemsCount ( ) ;
2018-05-02 01:16:09 -04:00
2018-12-12 20:45:19 +01:00
m_gridView - > scrollToTop ( ) ;
2019-01-07 20:56:23 +01:00
m_gridView - > setCurrentIndex ( m_proxyModel - > index ( 0 , 0 ) ) ;
}
void MainWindow : : updateItemsCount ( )
{
m_itemsCountLabel - > setText ( m_itemsCountLiteral . arg ( m_proxyModel - > rowCount ( ) ) ) ;
2018-04-30 14:33:05 -04:00
}
void MainWindow : : keyPressEvent ( QKeyEvent * event )
{
/*
if ( event - > key ( ) = = Qt : : Key_F5 )
{
event - > accept ( ) ;
hide ( ) ;
return ;
}
*/
QMainWindow : : keyPressEvent ( event ) ;
}
QSettings * MainWindow : : settings ( )
{
return m_settings ;
}
2018-05-07 02:36:00 -04:00
QString MainWindow : : getCurrentViewTypeString ( )
{
switch ( m_viewType )
{
case VIEW_TYPE_ICONS :
{
return QStringLiteral ( " icons " ) ;
}
case VIEW_TYPE_LIST :
default :
{
return QStringLiteral ( " list " ) ;
}
}
return QStringLiteral ( " list " ) ;
}
2018-12-12 20:45:19 +01:00
QString MainWindow : : getCurrentThumbnailTypeString ( )
{
switch ( m_thumbnailType )
{
case THUMBNAIL_TYPE_SCREENSHOT :
{
return QStringLiteral ( " screenshot " ) ;
}
case THUMBNAIL_TYPE_TITLE_SCREEN :
{
return QStringLiteral ( " title " ) ;
}
case THUMBNAIL_TYPE_BOXART :
default :
{
return QStringLiteral ( " boxart " ) ;
}
}
return QStringLiteral ( " list " ) ;
}
ThumbnailType MainWindow : : getThumbnailTypeFromString ( QString thumbnailType )
{
if ( thumbnailType = = " boxart " )
return THUMBNAIL_TYPE_BOXART ;
else if ( thumbnailType = = " screenshot " )
return THUMBNAIL_TYPE_SCREENSHOT ;
else if ( thumbnailType = = " title " )
return THUMBNAIL_TYPE_TITLE_SCREEN ;
return THUMBNAIL_TYPE_BOXART ;
}
2018-04-30 14:33:05 -04:00
void MainWindow : : closeEvent ( QCloseEvent * event )
{
if ( m_settings - > value ( " save_geometry " , false ) . toBool ( ) )
m_settings - > setValue ( " geometry " , saveGeometry ( ) ) ;
if ( m_settings - > value ( " save_dock_positions " , false ) . toBool ( ) )
m_settings - > setValue ( " dock_positions " , saveState ( ) ) ;
if ( m_settings - > value ( " save_last_tab " , false ) . toBool ( ) )
m_settings - > setValue ( " last_tab " , m_browserAndPlaylistTabWidget - > currentIndex ( ) ) ;
2018-05-07 02:36:00 -04:00
m_settings - > setValue ( " view_type " , getCurrentViewTypeString ( ) ) ;
2019-01-07 20:56:23 +01:00
m_settings - > setValue ( " file_browser_table_headers " , m_fileTableView - > horizontalHeader ( ) - > saveState ( ) ) ;
m_settings - > setValue ( " icon_view_zoom " , m_lastZoomSliderValue ) ;
2019-04-01 21:31:46 +02:00
m_settings - > setValue ( " icon_view_thumbnail_type " , getCurrentThumbnailTypeString ( ) ) ;
2018-05-07 02:36:00 -04:00
2018-04-30 14:33:05 -04:00
QMainWindow : : closeEvent ( event ) ;
}
2018-08-10 19:10:23 -04:00
void MainWindow : : onContributorsClicked ( )
{
QScopedPointer < QDialog > dialog ( new QDialog ( ) ) ;
QDialogButtonBox * buttonBox = new QDialogButtonBox ( QDialogButtonBox : : Ok ) ;
QTextEdit * textEdit = new QTextEdit ( dialog . data ( ) ) ;
connect ( buttonBox , SIGNAL ( accepted ( ) ) , dialog . data ( ) , SLOT ( accept ( ) ) ) ;
connect ( buttonBox , SIGNAL ( rejected ( ) ) , dialog . data ( ) , SLOT ( reject ( ) ) ) ;
dialog - > setWindowTitle ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_MENU_HELP_ABOUT_CONTRIBUTORS ) ) ;
dialog - > setLayout ( new QVBoxLayout ( ) ) ;
dialog - > layout ( ) - > addWidget ( textEdit ) ;
dialog - > layout ( ) - > addItem ( new QSpacerItem ( 20 , 20 , QSizePolicy : : Minimum , QSizePolicy : : Minimum ) ) ;
dialog - > layout ( ) - > addWidget ( buttonBox ) ;
textEdit - > setReadOnly ( true ) ;
textEdit - > setHtml ( QString ( " <pre> " ) + retroarch_contributors_list + " </pre> " ) ;
dialog - > resize ( 480 , 640 ) ;
dialog - > exec ( ) ;
}
2018-08-02 23:21:39 -04:00
void MainWindow : : showAbout ( )
{
QScopedPointer < QDialog > dialog ( new QDialog ( ) ) ;
QDialogButtonBox * buttonBox = new QDialogButtonBox ( QDialogButtonBox : : Ok ) ;
2018-08-03 21:14:27 -04:00
QString text = QString ( " RetroArch " ) + PACKAGE_VERSION +
" <br><br> " + " <a href= \" http://www.libretro.com/ \" >www.libretro.com</a> "
2018-08-10 19:10:23 -04:00
" <br><br> " + " <a href= \" http://www.retroarch.com/ \" >www.retroarch.com</a> "
2019-02-25 20:10:58 +01:00
# ifdef HAVE_GIT_VERSION
2019-02-15 16:41:52 -05:00
" <br><br> " + msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_GIT_VERSION ) + " : " + retroarch_git_version +
2019-02-25 20:10:58 +01:00
# endif
2019-02-15 16:41:52 -05:00
" <br> " + msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_BUILD_DATE ) + " : " + __DATE__ ;
2018-08-02 23:21:39 -04:00
QLabel * label = new QLabel ( text , dialog . data ( ) ) ;
QPixmap pix = getInvader ( ) ;
2018-08-10 19:10:23 -04:00
QLabel * pixLabel = new QLabel ( dialog . data ( ) ) ;
QPushButton * contributorsPushButton = new QPushButton ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_MENU_HELP_ABOUT_CONTRIBUTORS ) , dialog . data ( ) ) ;
connect ( contributorsPushButton , SIGNAL ( clicked ( ) ) , this , SLOT ( onContributorsClicked ( ) ) ) ;
connect ( buttonBox , SIGNAL ( accepted ( ) ) , dialog . data ( ) , SLOT ( accept ( ) ) ) ;
connect ( buttonBox , SIGNAL ( rejected ( ) ) , dialog . data ( ) , SLOT ( reject ( ) ) ) ;
2018-08-02 23:21:39 -04:00
label - > setTextFormat ( Qt : : RichText ) ;
label - > setAlignment ( Qt : : AlignCenter ) ;
2018-08-03 21:14:27 -04:00
label - > setTextInteractionFlags ( Qt : : TextBrowserInteraction ) ;
label - > setOpenExternalLinks ( true ) ;
2018-08-02 23:21:39 -04:00
pixLabel - > setAlignment ( Qt : : AlignCenter ) ;
pixLabel - > setPixmap ( pix ) ;
dialog - > setWindowTitle ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_MENU_HELP_ABOUT ) ) ;
dialog - > setLayout ( new QVBoxLayout ( ) ) ;
dialog - > layout ( ) - > addWidget ( pixLabel ) ;
dialog - > layout ( ) - > addWidget ( label ) ;
2018-08-10 19:10:23 -04:00
dialog - > layout ( ) - > addWidget ( contributorsPushButton ) ;
2018-08-02 23:21:39 -04:00
dialog - > layout ( ) - > addItem ( new QSpacerItem ( 20 , 20 , QSizePolicy : : Minimum , QSizePolicy : : Expanding ) ) ;
dialog - > layout ( ) - > addWidget ( buttonBox ) ;
dialog - > exec ( ) ;
}
2018-08-03 21:14:27 -04:00
void MainWindow : : showDocs ( )
{
2018-08-06 20:52:47 -04:00
QDesktopServices : : openUrl ( QUrl ( DOCS_URL ) ) ;
}
2018-08-09 11:55:42 -04:00
void MainWindow : : onShowErrorMessage ( QString msg )
{
showMessageBox ( msg , MainWindow : : MSGBOX_TYPE_ERROR , Qt : : ApplicationModal , false ) ;
2018-08-06 20:52:47 -04:00
}
2018-08-16 08:42:40 -04:00
void MainWindow : : onShowInfoMessage ( QString msg )
{
showMessageBox ( msg , MainWindow : : MSGBOX_TYPE_INFO , Qt : : ApplicationModal , false ) ;
}
2018-08-26 23:24:43 -04:00
int MainWindow : : onExtractArchive ( QString path , QString extractionDir , QString tempExtension , retro_task_callback_t cb )
{
QByteArray pathArray = path . toUtf8 ( ) ;
QByteArray dirArray = extractionDir . toUtf8 ( ) ;
const char * file = pathArray . constData ( ) ;
const char * dir = dirArray . constData ( ) ;
file_archive_transfer_t state ;
struct archive_extract_userdata userdata ;
struct string_list * file_list = file_archive_get_file_list ( file , NULL ) ;
bool returnerr = true ;
unsigned i ;
if ( ! file_list | | file_list - > size = = 0 )
{
showMessageBox ( " Error: Archive is empty. " , MainWindow : : MSGBOX_TYPE_ERROR , Qt : : ApplicationModal , false ) ;
RARCH_ERR ( " [Qt]: Downloaded archive is empty? \n " ) ;
return - 1 ;
}
for ( i = 0 ; i < file_list - > size ; i + + )
{
QFile fileObj ( file_list - > elems [ i ] . data ) ;
if ( fileObj . exists ( ) )
{
if ( ! fileObj . remove ( ) )
{
/* if we cannot delete the existing file to update it, rename it for now and delete later */
QFile fileTemp ( fileObj . fileName ( ) + tempExtension ) ;
if ( fileTemp . exists ( ) )
{
if ( ! fileTemp . remove ( ) )
{
showMessageBox ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE ) , MainWindow : : MSGBOX_TYPE_ERROR , Qt : : ApplicationModal , false ) ;
RARCH_ERR ( " [Qt]: Could not delete file: %s \n " , file_list - > elems [ i ] . data ) ;
return - 1 ;
}
}
if ( ! fileObj . rename ( fileTemp . fileName ( ) ) )
{
showMessageBox ( msg_hash_to_str ( MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_RENAME_FILE ) , MainWindow : : MSGBOX_TYPE_ERROR , Qt : : ApplicationModal , false ) ;
RARCH_ERR ( " [Qt]: Could not rename file: %s \n " , file_list - > elems [ i ] . data ) ;
return - 1 ;
}
}
}
}
string_list_free ( file_list ) ;
memset ( & state , 0 , sizeof ( state ) ) ;
memset ( & userdata , 0 , sizeof ( userdata ) ) ;
state . type = ARCHIVE_TRANSFER_INIT ;
m_updateProgressDialog - > setWindowModality ( Qt : : NonModal ) ;
m_updateProgressDialog - > setMinimumDuration ( 0 ) ;
m_updateProgressDialog - > setRange ( 0 , 0 ) ;
m_updateProgressDialog - > setAutoClose ( true ) ;
m_updateProgressDialog - > setAutoReset ( true ) ;
m_updateProgressDialog - > setValue ( 0 ) ;
m_updateProgressDialog - > setLabelText ( QString ( msg_hash_to_str ( MSG_EXTRACTING ) ) + " ... " ) ;
m_updateProgressDialog - > setCancelButtonText ( QString ( ) ) ;
m_updateProgressDialog - > show ( ) ;
if ( ! task_push_decompress ( file , dir ,
NULL , NULL , NULL ,
2018-11-22 15:45:52 +01:00
cb , this , NULL ) )
2018-08-26 23:24:43 -04:00
{
m_updateProgressDialog - > cancel ( ) ;
return - 1 ;
}
return returnerr ;
}
2018-08-29 00:42:34 -04:00
QString MainWindow : : getScrubbedString ( QString str )
{
2018-08-29 18:41:05 -04:00
const QString chars ( " &*/:` \" <>? \\ | " ) ;
int i ;
2018-08-29 00:42:34 -04:00
2018-08-29 18:41:05 -04:00
for ( i = 0 ; i < chars . count ( ) ; i + + )
2018-08-29 00:42:34 -04:00
{
2018-08-29 18:41:05 -04:00
str . replace ( chars . at ( i ) , ' _ ' ) ;
2018-08-29 00:42:34 -04:00
}
return str ;
}
2018-04-30 14:33:05 -04:00
static void * ui_window_qt_init ( void )
{
ui_window . qtWindow = new MainWindow ( ) ;
return & ui_window ;
}
2016-06-09 20:11:26 +02:00
static void ui_window_qt_destroy ( void * data )
{
2018-04-30 14:33:05 -04:00
( void ) data ;
/*
2016-06-10 10:22:49 +02:00
ui_window_qt_t * window = ( ui_window_qt_t * ) data ;
delete window - > qtWindow ;
2018-04-30 14:33:05 -04:00
*/
2016-06-09 20:11:26 +02:00
}
static void ui_window_qt_set_focused ( void * data )
{
2018-04-30 14:33:05 -04:00
( void ) data ;
/*
2016-06-10 10:22:49 +02:00
ui_window_qt_t * window = ( ui_window_qt_t * ) data ;
window - > qtWindow - > raise ( ) ;
window - > qtWindow - > activateWindow ( ) ;
2018-04-30 14:33:05 -04:00
*/
2016-06-09 20:11:26 +02:00
}
static void ui_window_qt_set_visible ( void * data ,
bool set_visible )
{
2018-04-30 14:33:05 -04:00
( void ) data ;
( void ) set_visible ;
2016-06-10 10:22:49 +02:00
/* TODO/FIXME */
2016-06-09 20:11:26 +02:00
}
static void ui_window_qt_set_title ( void * data , char * buf )
{
2018-04-30 14:33:05 -04:00
( void ) data ;
( void ) buf ;
/*
2016-06-10 10:22:49 +02:00
ui_window_qt_t * window = ( ui_window_qt_t * ) data ;
window - > qtWindow - > setWindowTitle ( QString : : fromUtf8 ( buf ) ) ;
2018-04-30 14:33:05 -04:00
*/
2016-06-09 20:11:26 +02:00
}
static void ui_window_qt_set_droppable ( void * data , bool droppable )
{
2018-04-30 14:33:05 -04:00
( void ) data ;
( void ) droppable ;
/*
2016-06-10 10:22:49 +02:00
ui_window_qt_t * window = ( ui_window_qt_t * ) data ;
2018-04-30 14:33:05 -04:00
window - > qtWindow - > setAcceptDrops ( droppable ) ;
*/
2016-06-09 20:11:26 +02:00
}
static bool ui_window_qt_focused ( void * data )
{
2018-04-30 14:33:05 -04:00
( void ) data ;
/*
2016-06-10 10:22:49 +02:00
ui_window_qt_t * window = ( ui_window_qt_t * ) data ;
return window - > qtWindow - > isActiveWindow ( ) & & ! window - > qtWindow - > isMinimized ( ) ;
2018-04-30 14:33:05 -04:00
*/
return true ;
2016-06-09 20:11:26 +02:00
}
2018-04-30 14:33:05 -04:00
ui_window_t ui_window_qt = {
ui_window_qt_init ,
2016-06-09 20:11:26 +02:00
ui_window_qt_destroy ,
ui_window_qt_set_focused ,
ui_window_qt_set_visible ,
ui_window_qt_set_title ,
ui_window_qt_set_droppable ,
ui_window_qt_focused ,
" qt "
} ;