From d1a426d6658c7e674afb68da5a3c644b6b67bcc1 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 9 Mar 2014 16:35:15 +0000 Subject: enabled 'file types' page, removed unused code git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4140 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmpui/configdialog.cpp | 5 +- src/qmmpui/forms/prefassociations.ui | 77 -------- src/qmmpui/forms/winfileassocpage.ui | 77 ++++++++ src/qmmpui/prefassociations.cpp | 239 ------------------------ src/qmmpui/prefassociations.h | 72 -------- src/qmmpui/qmmpui.pro | 339 ++++++++++++++++++----------------- src/qmmpui/winfileassoc.cpp | 8 +- src/qmmpui/winfileassocpage.cpp | 151 ++++++++++++++++ src/qmmpui/winfileassocpage_p.h | 57 ++++++ 9 files changed, 465 insertions(+), 560 deletions(-) delete mode 100644 src/qmmpui/forms/prefassociations.ui create mode 100644 src/qmmpui/forms/winfileassocpage.ui delete mode 100644 src/qmmpui/prefassociations.cpp delete mode 100644 src/qmmpui/prefassociations.h create mode 100644 src/qmmpui/winfileassocpage.cpp create mode 100644 src/qmmpui/winfileassocpage_p.h (limited to 'src') diff --git a/src/qmmpui/configdialog.cpp b/src/qmmpui/configdialog.cpp index 6d113aa31..676310646 100644 --- a/src/qmmpui/configdialog.cpp +++ b/src/qmmpui/configdialog.cpp @@ -51,7 +51,7 @@ #include "mediaplayer.h" #include "qmmpuisettings.h" #include "playlistmodel.h" -#include "prefassociations.h" +#include "winfileassocpage_p.h" #include "configdialog.h" ConfigDialog::ConfigDialog (QWidget *parent) : QDialog (parent) @@ -77,8 +77,7 @@ ConfigDialog::ConfigDialog (QWidget *parent) : QDialog (parent) m_ui->informationButton->setIcon(QIcon::fromTheme("dialog-information")); //file associations #ifdef Q_OS_WIN - QWidget *widget = new PrefAssociations(this); - m_ui->stackedWidget->addWidget(widget); + m_ui->stackedWidget->addWidget(new WinFileAssocPage(this)); m_ui->contentsWidget->addItem(tr("File Types")); m_ui->contentsWidget->item(m_ui->contentsWidget->count() - 1)->setIcon(QIcon(":associations.png")); #endif diff --git a/src/qmmpui/forms/prefassociations.ui b/src/qmmpui/forms/prefassociations.ui deleted file mode 100644 index 2960b6bda..000000000 --- a/src/qmmpui/forms/prefassociations.ui +++ /dev/null @@ -1,77 +0,0 @@ - - - PrefAssociations - - - - 0 - 0 - 547 - 348 - - - - - - - Media files handled by Qmmp: - - - Qt::AlignVCenter - - - true - - - - - - - QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed - - - QAbstractItemView::MultiSelection - - - QListView::ListMode - - - true - - - true - - - - - - - Select All - - - - - - - Select None - - - - - - - Qt::Horizontal - - - - 364 - 20 - - - - - - - - - diff --git a/src/qmmpui/forms/winfileassocpage.ui b/src/qmmpui/forms/winfileassocpage.ui new file mode 100644 index 000000000..1629baccc --- /dev/null +++ b/src/qmmpui/forms/winfileassocpage.ui @@ -0,0 +1,77 @@ + + + WinFileAssocPage + + + + 0 + 0 + 547 + 348 + + + + + + + Media files handled by Qmmp: + + + Qt::AlignVCenter + + + true + + + + + + + QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed + + + QAbstractItemView::MultiSelection + + + QListView::ListMode + + + true + + + true + + + + + + + Select All + + + + + + + Select None + + + + + + + Qt::Horizontal + + + + 364 + 20 + + + + + + + + + diff --git a/src/qmmpui/prefassociations.cpp b/src/qmmpui/prefassociations.cpp deleted file mode 100644 index 89c12bca2..000000000 --- a/src/qmmpui/prefassociations.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* smplayer, GUI front-end for mplayer. - Copyright (C) 2006-2014 Ricardo Villalba - - This program 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 Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - - prefassociations.cpp - Handles file associations in Windows - Author: Florin Braghis (florin@libertv.ro) -*/ - - -#include "prefassociations.h" -//#include "images.h" -#include -#include -#include -#include "winfileassoc.h" -//#include "extensions.h" - -static Qt::CheckState CurItemCheckState = Qt::Unchecked; - - -PrefAssociations::PrefAssociations(QWidget * parent, Qt::WindowFlags f) -: QWidget(parent, f ) -{ - setupUi(this); - - connect(selectAll, SIGNAL(clicked(bool)), this, SLOT(selectAllClicked(bool))); - connect(selectNone, SIGNAL(clicked(bool)), this, SLOT(selectNoneClicked(bool))); - connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(listItemClicked(QListWidgetItem*))); - connect(listWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(listItemPressed(QListWidgetItem*))); - - if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) - { - //Hide Select None - One cannot restore an association in Vista. Go figure. - selectNone->hide(); - //QPushButton* lpbButton = new QPushButton("Launch Program Defaults", this); - //hboxLayout->addWidget(lpbButton); - //connect(lpbButton, SIGNAL(clicked(bool)), this, SLOT(launchAppDefaults())); - } - - /*Extensions e; - for (int n=0; n < e.multimedia().count(); n++) { - addItem( e.multimedia()[n] ); - } - // Add the playlist extensions - for (int n=0; n < e.playlist().count(); n++) { - addItem( e.playlist()[n] ); - } - retranslateStrings();*/ - - something_changed = false; -} - -PrefAssociations::~PrefAssociations() -{ - -} - -void PrefAssociations::selectAllClicked(bool) -{ - for (int k = 0; k < listWidget->count(); k++) - listWidget->item(k)->setCheckState(Qt::Checked); - listWidget->setFocus(); - - something_changed = true; -} - -void PrefAssociations::selectNoneClicked(bool) -{ - - for (int k = 0; k < listWidget->count(); k++) - listWidget->item(k)->setCheckState(Qt::Unchecked); - listWidget->setFocus(); - - something_changed = true; -} - -void PrefAssociations::listItemClicked(QListWidgetItem* item) -{ - qDebug("PrefAssociations::listItemClicked"); - - if (!(item->flags() & Qt::ItemIsEnabled)) - return; - - if (item->checkState() == CurItemCheckState) - { - //Clicked on the list item (not checkbox) - if (item->checkState() == Qt::Checked) - { - item->setCheckState(Qt::Unchecked); - } - else - item->setCheckState(Qt::Checked); - } - - //else - clicked on the checkbox itself, do nothing - - something_changed = true; -} - -void PrefAssociations::listItemPressed(QListWidgetItem* item) -{ - CurItemCheckState = item->checkState(); -} - -void PrefAssociations::addItem(QString label) -{ - QListWidgetItem* item = new QListWidgetItem(listWidget); - item->setText(label); -} - -void PrefAssociations::refreshList() -{ - m_regExtensions.clear(); - //WinFileAssoc ().GetRegisteredExtensions(Extensions().multimedia(), m_regExtensions); - - for (int k = 0; k < listWidget->count(); k++) - { - QListWidgetItem* pItem = listWidget->item(k); - if (pItem) - { - pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); - - if (m_regExtensions.contains(pItem->text())) - { - pItem->setCheckState(Qt::Checked); - //Don't allow de-selection in windows VISTA if extension is registered. - //VISTA doesn't seem to support extension 'restoration' in the API. - if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) { - pItem->setFlags(0); - } - } - else - { - pItem->setCheckState(Qt::Unchecked); - } - - } - } -} - -void PrefAssociations::setData(Preferences * ) -{ - refreshList(); -} - -int PrefAssociations::ProcessAssociations(QStringList& current, QStringList& old) -{ - WinFileAssoc RegAssoc; - - QStringList toRestore; - - //Restore unselected associations - foreach(const QString& ext, old) - { - if (!current.contains(ext)) - toRestore.append(ext); - } - - RegAssoc.RestoreFileAssociations(toRestore); - return RegAssoc.CreateFileAssociations(current); -} - -void PrefAssociations::getData(Preferences *) -{ - qDebug("PrefAssociations::getData: something_changed: %d", something_changed); - if (!something_changed) return; - - QStringList extensions; - - for (int k = 0; k < listWidget->count(); k++) - { - QListWidgetItem* pItem = listWidget->item(k); - if (pItem && pItem->checkState() == Qt::Checked) - extensions.append(pItem->text()); - } - - int processed = ProcessAssociations(extensions, m_regExtensions); - - if (processed != extensions.count()) - { - QMessageBox::warning(this, tr("Warning"), - tr("Not all files could be associated. Please check your " - "security permissions and retry."), QMessageBox::Ok); - } - - refreshList(); //Useless when OK is pressed... How to detect if apply or ok is pressed ? - - something_changed = false; -} - -QString PrefAssociations::sectionName() { - return tr("File Types"); -} - -/*QPixmap PrefAssociations::sectionIcon() { - return Images::icon("pref_associations", 22); -}*/ - -/*void PrefAssociations::retranslateStrings() { - - retranslateUi(this); - createHelp(); -}*/ - -void PrefAssociations::createHelp() { - - //clearHelp(); - - /*setWhatsThis(selectAll, tr("Select all"), - tr("Check all file types in the list")); - - setWhatsThis(selectNone, tr("Select none"), - tr("Uncheck all file types in the list")); - - setWhatsThis(listWidget, tr("List of file types"), - tr("Check the media file extensions you would like SMPlayer to handle. " - "When you click Apply, the checked files will be associated with " - "SMPlayer. If you uncheck a media type, the file association will " - "be restored.") + - tr(" Note: (Restoration doesn't work on Windows Vista)."));*/ -} - -#include "moc_prefassociations.cpp" - diff --git a/src/qmmpui/prefassociations.h b/src/qmmpui/prefassociations.h deleted file mode 100644 index ff44677fa..000000000 --- a/src/qmmpui/prefassociations.h +++ /dev/null @@ -1,72 +0,0 @@ -/* smplayer, GUI front-end for mplayer. - Copyright (C) 2006-2014 Ricardo Villalba - - This program 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 Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - - prefassociations.h - Handles file associations in Windows - Author: Florin Braghis (florin@libertv.ro) -*/ - -#ifndef _PREFASSOCIATIONS_H_ -#define _PREFASSOCIATIONS_H_ - -#include "ui_prefassociations.h" -//#include "prefwidget.h" - -class Preferences; - -class PrefAssociations : public QWidget, public Ui::PrefAssociations -{ - Q_OBJECT - -public: - PrefAssociations( QWidget * parent = 0, Qt::WindowFlags f = 0 ); - ~PrefAssociations(); - - virtual QString sectionName(); - //virtual QPixmap sectionIcon(); - - // Pass data to the dialog - void setData(Preferences * pref); - - // Apply changes - void getData(Preferences * pref); - - void addItem(QString label); - - int ProcessAssociations(QStringList& current, QStringList& old); - void refreshList(); - -protected: - QStringList m_regExtensions; -protected: - virtual void createHelp(); - -/*protected: - virtual void retranslateStrings();*/ - -public slots: - void selectAllClicked(bool); - void selectNoneClicked(bool); - void listItemClicked(QListWidgetItem* item); - void listItemPressed(QListWidgetItem* item); - -protected: - bool something_changed; -}; - -#endif diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index 3733b2b2d..c09bcacd5 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -1,168 +1,171 @@ -include(../../qmmp.pri) - -VERSION = $$QMMP_VERSION -INCLUDEPATH += ../ -TEMPLATE = lib -QT += network - -CONFIG += warn_on \ - shared \ - create_pc create_prl no_install_prl \ - qt \ - thread - -QMAKE_LIBDIR += ../../lib \ - qmmpui - -LIBS += -Wl,-rpath,./ - -unix { - TARGET = ../../lib/qmmpui - LIBS += -L../../lib -lqmmp - isEmpty(LIB_DIR):LIB_DIR = /lib - target.path = $$LIB_DIR -} - -win32 { - TARGET = ../../../bin/qmmpui - LIBS += -L../../bin -lqmmp0 -lole32 - HEADERS += winfileassoc.h \ - prefassociations.h - SOURCES += winfileassoc.cpp \ - prefassociations.cpp - FORMS += forms/prefassociations.ui -} - -HEADERS += general.h \ - generalfactory.h \ - playlistformat.h \ - playlistparser.h \ - commandlinemanager.h \ - commandlineoption.h \ - filedialog.h \ - filedialogfactory.h \ - qtfiledialog_p.h \ - playlistitem.h \ - playlistmodel.h \ - playstate_p.h \ - fileloader_p.h \ - mediaplayer.h \ - detailsdialog.h \ - tageditor_p.h \ - playlistmanager.h \ - metadataformatter.h \ - templateeditor.h \ - uifactory.h \ - uiloader.h \ - uihelper.h \ - jumptotrackdialog_p.h \ - configdialog.h \ - pluginitem_p.h \ - aboutdialog_p.h \ - qmmpuisettings.h \ - radioitemdelegate_p.h \ - playlistdownloader.h \ - addurldialog_p.h \ - qmmpuiplugincache_p.h \ - tagupdater_p.h \ - playlistgroup.h \ - playlisttrack.h \ - playlistcontainer_p.h \ - groupedcontainer_p.h \ - normalcontainer_p.h -SOURCES += general.cpp \ - playlistparser.cpp \ - commandlinemanager.cpp \ - filedialog.cpp \ - qtfiledialog.cpp \ - playlistmodel.cpp \ - playstate.cpp \ - playlistitem.cpp \ - fileloader.cpp \ - mediaplayer.cpp \ - detailsdialog.cpp \ - tageditor.cpp \ - playlistmanager.cpp \ - metadataformatter.cpp \ - templateeditor.cpp \ - uiloader.cpp \ - uihelper.cpp \ - jumptotrackdialog.cpp \ - configdialog.cpp \ - pluginitem.cpp \ - aboutdialog.cpp \ - qmmpuisettings.cpp \ - radioitemdelegate.cpp \ - playlistdownloader.cpp \ - addurldialog.cpp \ - qmmpuiplugincache.cpp \ - tagupdater.cpp \ - playlistgroup.cpp \ - playlisttrack.cpp \ - groupedcontainer.cpp \ - normalcontainer.cpp \ - playlistcontainer.cpp -FORMS += forms/detailsdialog.ui \ - forms/tageditor.ui \ - forms/templateeditor.ui \ - forms/jumptotrackdialog.ui \ - forms/configdialog.ui \ - forms/aboutdialog.ui \ - forms/addurldialog.ui -unix:DESTDIR = . -RESOURCES += translations/libqmmpui_locales.qrc \ - images/qmmpui_images.qrc \ - txt/txt.qrc -TRANSLATIONS = translations/libqmmpui_ru.ts \ - translations/libqmmpui_tr.ts \ - translations/libqmmpui_zh_CN.ts \ - translations/libqmmpui_cs.ts \ - translations/libqmmpui_pt_BR.ts \ - translations/libqmmpui_uk_UA.ts \ - translations/libqmmpui_zh_TW.ts \ - translations/libqmmpui_de.ts \ - translations/libqmmpui_it.ts \ - translations/libqmmpui_lt.ts \ - translations/libqmmpui_pl_PL.ts \ - translations/libqmmpui_nl.ts \ - translations/libqmmpui_ja.ts \ - translations/libqmmpui_es.ts \ - translations/libqmmpui_sk.ts \ - translations/libqmmpui_sr_BA.ts \ - translations/libqmmpui_sr_RS.ts -unix { - devel.files += general.h \ - generalfactory.h \ - playlistformat.h \ - playlistparser.h \ - commandlinemanager.h \ - commandlineoption.h \ - filedialog.h \ - filedialogfactory.h \ - playlistitem.h \ - playlistmodel.h \ - mediaplayer.h \ - detailsdialog.h \ - playlistmanager.h \ - metadataformatter.h \ - templateeditor.h \ - uifactory.h \ - uiloader.h \ - uihelper.h \ - configdialog.h \ - qmmpuisettings.h \ - playlistdownloader.h \ - playlistgroup.h \ - playlisttrack.h - - devel.path = /include/qmmpui - INSTALLS += target \ - devel -} - -unix { - QMAKE_PKGCONFIG_NAME = qmmpui - QMAKE_PKGCONFIG_DESCRIPTION = qmmp user interface library - QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtNetwork qmmp - QMAKE_PKGCONFIG_DESTDIR = pkgconfig -} +include(../../qmmp.pri) + +VERSION = $$QMMP_VERSION +INCLUDEPATH += ../ +TEMPLATE = lib +QT += network + +CONFIG += warn_on \ + shared \ + create_pc create_prl no_install_prl \ + qt \ + thread + +QMAKE_LIBDIR += ../../lib \ + qmmpui + +LIBS += -Wl,-rpath,./ + +unix { + TARGET = ../../lib/qmmpui + LIBS += -L../../lib -lqmmp + isEmpty(LIB_DIR):LIB_DIR = /lib + target.path = $$LIB_DIR +} + +win32 { + TARGET = ../../../bin/qmmpui + LIBS += -L../../bin -lqmmp0 -lole32 + HEADERS += winfileassoc.h \ + winfileassocpage_p.h + SOURCES += winfileassoc.cpp \ + winfileassocpage.cpp + FORMS += forms/winfileassocpage.ui +} + +HEADERS += general.h \ + generalfactory.h \ + playlistformat.h \ + playlistparser.h \ + commandlinemanager.h \ + commandlineoption.h \ + filedialog.h \ + filedialogfactory.h \ + qtfiledialog_p.h \ + playlistitem.h \ + playlistmodel.h \ + playstate_p.h \ + fileloader_p.h \ + mediaplayer.h \ + detailsdialog.h \ + tageditor_p.h \ + playlistmanager.h \ + metadataformatter.h \ + templateeditor.h \ + uifactory.h \ + uiloader.h \ + uihelper.h \ + jumptotrackdialog_p.h \ + configdialog.h \ + pluginitem_p.h \ + aboutdialog_p.h \ + qmmpuisettings.h \ + radioitemdelegate_p.h \ + playlistdownloader.h \ + addurldialog_p.h \ + qmmpuiplugincache_p.h \ + tagupdater_p.h \ + playlistgroup.h \ + playlisttrack.h \ + playlistcontainer_p.h \ + groupedcontainer_p.h \ + normalcontainer_p.h + +SOURCES += general.cpp \ + playlistparser.cpp \ + commandlinemanager.cpp \ + filedialog.cpp \ + qtfiledialog.cpp \ + playlistmodel.cpp \ + playstate.cpp \ + playlistitem.cpp \ + fileloader.cpp \ + mediaplayer.cpp \ + detailsdialog.cpp \ + tageditor.cpp \ + playlistmanager.cpp \ + metadataformatter.cpp \ + templateeditor.cpp \ + uiloader.cpp \ + uihelper.cpp \ + jumptotrackdialog.cpp \ + configdialog.cpp \ + pluginitem.cpp \ + aboutdialog.cpp \ + qmmpuisettings.cpp \ + radioitemdelegate.cpp \ + playlistdownloader.cpp \ + addurldialog.cpp \ + qmmpuiplugincache.cpp \ + tagupdater.cpp \ + playlistgroup.cpp \ + playlisttrack.cpp \ + groupedcontainer.cpp \ + normalcontainer.cpp \ + playlistcontainer.cpp + +FORMS += forms/detailsdialog.ui \ + forms/tageditor.ui \ + forms/templateeditor.ui \ + forms/jumptotrackdialog.ui \ + forms/configdialog.ui \ + forms/aboutdialog.ui \ + forms/addurldialog.ui + +unix:DESTDIR = . +RESOURCES += translations/libqmmpui_locales.qrc \ + images/qmmpui_images.qrc \ + txt/txt.qrc +TRANSLATIONS = translations/libqmmpui_ru.ts \ + translations/libqmmpui_tr.ts \ + translations/libqmmpui_zh_CN.ts \ + translations/libqmmpui_cs.ts \ + translations/libqmmpui_pt_BR.ts \ + translations/libqmmpui_uk_UA.ts \ + translations/libqmmpui_zh_TW.ts \ + translations/libqmmpui_de.ts \ + translations/libqmmpui_it.ts \ + translations/libqmmpui_lt.ts \ + translations/libqmmpui_pl_PL.ts \ + translations/libqmmpui_nl.ts \ + translations/libqmmpui_ja.ts \ + translations/libqmmpui_es.ts \ + translations/libqmmpui_sk.ts \ + translations/libqmmpui_sr_BA.ts \ + translations/libqmmpui_sr_RS.ts +unix { + devel.files += general.h \ + generalfactory.h \ + playlistformat.h \ + playlistparser.h \ + commandlinemanager.h \ + commandlineoption.h \ + filedialog.h \ + filedialogfactory.h \ + playlistitem.h \ + playlistmodel.h \ + mediaplayer.h \ + detailsdialog.h \ + playlistmanager.h \ + metadataformatter.h \ + templateeditor.h \ + uifactory.h \ + uiloader.h \ + uihelper.h \ + configdialog.h \ + qmmpuisettings.h \ + playlistdownloader.h \ + playlistgroup.h \ + playlisttrack.h + + devel.path = /include/qmmpui + INSTALLS += target \ + devel +} + +unix { + QMAKE_PKGCONFIG_NAME = qmmpui + QMAKE_PKGCONFIG_DESCRIPTION = qmmp user interface library + QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtNetwork qmmp + QMAKE_PKGCONFIG_DESTDIR = pkgconfig +} diff --git a/src/qmmpui/winfileassoc.cpp b/src/qmmpui/winfileassoc.cpp index 50e2b42f6..6b84b5db3 100644 --- a/src/qmmpui/winfileassoc.cpp +++ b/src/qmmpui/winfileassoc.cpp @@ -36,6 +36,12 @@ Author: Florin Braghis (florin@libertv.ro) */ +/* + main changes compared to SMplayer: + replaced SMPlayer by Qmmp +*/ + + #include "winfileassoc.h" #include #include @@ -252,7 +258,7 @@ bool WinFileAssoc::CreateClassId(const QString &executablePath, const QString &f // Add "Enqueue" command Reg.setValue(classId + "/shell/enqueue/.", QObject::tr("Enqueue in Qmmp")); - Reg.setValue(classId + "/shell/enqueue/command/.", QString("\"%1\" -add-to-playlist \"%2\"").arg(appPath, "%1")); + Reg.setValue(classId + "/shell/enqueue/command/.", QString("\"%1\" -e \"%2\"").arg(appPath, "%1")); return true; } diff --git a/src/qmmpui/winfileassocpage.cpp b/src/qmmpui/winfileassocpage.cpp new file mode 100644 index 000000000..a409472fc --- /dev/null +++ b/src/qmmpui/winfileassocpage.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** + * Based on smplayer - GUI front-end for mplayer * + * * + * Copyright (C) 2006-2014 Ricardo Villalba * + * Copyright (C) 2014 Ilya Kotov forkotov02@hotmail.ru * + * * + * This program 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 Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include "ui_winfileassocpage.h" +#include "winfileassocpage_p.h" +#include "winfileassoc.h" + +WinFileAssocPage::WinFileAssocPage(QWidget *parent): QWidget(parent) +{ + m_ui = new Ui::WinFileAssocPage; + m_ui->setupUi(this); + + if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) + { + //Hide Select None - One cannot restore an association in Vista. Go figure. + m_ui->selectNone->hide(); + } + + foreach (QString ext, MetaDataManager::instance()->nameFilters()) + { + ext.remove("*."); + m_ui->listWidget->addItem(ext); + m_extensions.append(ext); + } + loadAssociations(); + createHelp(); +} + +WinFileAssocPage::~WinFileAssocPage() +{ + saveAssociations(); +} + +void WinFileAssocPage::on_selectAll_clicked() +{ + for (int k = 0; k < m_ui->listWidget->count(); k++) + m_ui->listWidget->item(k)->setCheckState(Qt::Checked); + m_ui->listWidget->setFocus(); +} + +void WinFileAssocPage::on_selectNone_clicked() +{ + for (int k = 0; k < m_ui->listWidget->count(); k++) + m_ui->listWidget->item(k)->setCheckState(Qt::Unchecked); + m_ui->listWidget->setFocus(); +} + +void WinFileAssocPage::loadAssociations() +{ + m_regExtensions.clear(); + WinFileAssoc ().GetRegisteredExtensions(m_extensions, m_regExtensions); + + for (int k = 0; k < m_ui->listWidget->count(); k++) + { + QListWidgetItem* pItem = m_ui->listWidget->item(k); + if (pItem) + { + pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); + + if (m_regExtensions.contains(pItem->text())) + { + pItem->setCheckState(Qt::Checked); + //Don't allow de-selection in windows VISTA if extension is registered. + //VISTA doesn't seem to support extension 'restoration' in the API. + if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) + { + pItem->setFlags(0); + } + } + else + { + pItem->setCheckState(Qt::Unchecked); + } + } + } +} + +int WinFileAssocPage::ProcessAssociations(QStringList& current, QStringList& old) +{ + WinFileAssoc RegAssoc; + + QStringList toRestore; + + //Restore unselected associations + foreach(const QString& ext, old) + { + if (!current.contains(ext)) + toRestore.append(ext); + } + + RegAssoc.RestoreFileAssociations(toRestore); + return RegAssoc.CreateFileAssociations(current); +} + +void WinFileAssocPage::saveAssociations() +{ + QStringList extensions; + + for (int k = 0; k < m_ui->listWidget->count(); k++) + { + QListWidgetItem* pItem = m_ui->listWidget->item(k); + if (pItem && pItem->checkState() == Qt::Checked) + extensions.append(pItem->text()); + } + + if(extensions == m_regExtensions) + return; + + int processed = ProcessAssociations(extensions, m_regExtensions); + + if (processed != extensions.count()) + { + QMessageBox::warning(this, tr("Warning"), + tr("Not all files could be associated. Please check your " + "security permissions and retry."), QMessageBox::Ok); + } +} + +void WinFileAssocPage::createHelp() +{ + m_ui->selectAll->setToolTip(tr("Check all file types in the list")); + m_ui->selectNone->setToolTip(tr("Uncheck all file types in the list")); + m_ui->listWidget->setToolTip(tr("Check the media file extensions you would like Qmmp to handle. " + "When you click Apply, the checked files will be associated with " + "Qmmp. If you uncheck a media type, the file association will " + "be restored.") + "
" + + tr("Note: Restoration doesn't work on Windows Vista/7.")); +} diff --git a/src/qmmpui/winfileassocpage_p.h b/src/qmmpui/winfileassocpage_p.h new file mode 100644 index 000000000..a65e63085 --- /dev/null +++ b/src/qmmpui/winfileassocpage_p.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2014 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program 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 Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef WINFILEASSOCPAGE_P_H +#define WINFILEASSOCPAGE_P_H + +#include +#include + +namespace Ui { +class WinFileAssocPage; +} + +class QListWidgetItem; + +/*! @internal + */ +class WinFileAssocPage : public QWidget +{ + Q_OBJECT +public: + WinFileAssocPage(QWidget *parent = 0); + virtual ~WinFileAssocPage(); + + +private slots: + void on_selectAll_clicked(); + void on_selectNone_clicked(); + +private: + void loadAssociations(); + void saveAssociations(); + int ProcessAssociations(QStringList& current, QStringList& old); + void createHelp(); + QStringList m_extensions; + QStringList m_regExtensions; + Ui::WinFileAssocPage *m_ui; +}; + +#endif -- cgit v1.2.3-13-gbd6f