| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 | prefassociations.cpp
|
|---|
| 20 | Handles file associations in Windows
|
|---|
| 21 | Author: Florin Braghis (florin@libertv.ro)
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | #include "prefassociations.h"
|
|---|
| 26 | #include "images.h"
|
|---|
| 27 | #include <QSettings>
|
|---|
| 28 | #include <QApplication>
|
|---|
| 29 | #include <QMessageBox>
|
|---|
| 30 | #include "winfileassoc.h"
|
|---|
| 31 | #include "extensions.h"
|
|---|
| 32 |
|
|---|
| 33 | static Qt::CheckState CurItemCheckState = Qt::Unchecked;
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | PrefAssociations::PrefAssociations(QWidget * parent, Qt::WindowFlags f)
|
|---|
| 37 | : PrefWidget(parent, f )
|
|---|
| 38 | {
|
|---|
| 39 | setupUi(this);
|
|---|
| 40 |
|
|---|
| 41 | connect(selectAll, SIGNAL(clicked(bool)), this, SLOT(selectAllClicked(bool)));
|
|---|
| 42 | connect(selectNone, SIGNAL(clicked(bool)), this, SLOT(selectNoneClicked(bool)));
|
|---|
| 43 | connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(listItemClicked(QListWidgetItem*)));
|
|---|
| 44 | connect(listWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(listItemPressed(QListWidgetItem*)));
|
|---|
| 45 |
|
|---|
| 46 | if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
|
|---|
| 47 | {
|
|---|
| 48 | //Hide Select None - One cannot restore an association in Vista. Go figure.
|
|---|
| 49 | selectNone->hide();
|
|---|
| 50 | //QPushButton* lpbButton = new QPushButton("Launch Program Defaults", this);
|
|---|
| 51 | //hboxLayout->addWidget(lpbButton);
|
|---|
| 52 | //connect(lpbButton, SIGNAL(clicked(bool)), this, SLOT(launchAppDefaults()));
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | Extensions e;
|
|---|
| 56 | for (int n=0; n < e.multimedia().count(); n++) {
|
|---|
| 57 | addItem( e.multimedia()[n] );
|
|---|
| 58 | }
|
|---|
| 59 | // Add the playlist extensions
|
|---|
| 60 | for (int n=0; n < e.playlist().count(); n++) {
|
|---|
| 61 | addItem( e.playlist()[n] );
|
|---|
| 62 | }
|
|---|
| 63 | retranslateStrings();
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | PrefAssociations::~PrefAssociations()
|
|---|
| 67 | {
|
|---|
| 68 |
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | void PrefAssociations::selectAllClicked(bool)
|
|---|
| 72 | {
|
|---|
| 73 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 74 | listWidget->item(k)->setCheckState(Qt::Checked);
|
|---|
| 75 | listWidget->setFocus();
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | void PrefAssociations::selectNoneClicked(bool)
|
|---|
| 79 | {
|
|---|
| 80 |
|
|---|
| 81 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 82 | listWidget->item(k)->setCheckState(Qt::Unchecked);
|
|---|
| 83 | listWidget->setFocus();
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void PrefAssociations::listItemClicked(QListWidgetItem* item)
|
|---|
| 87 | {
|
|---|
| 88 | if (!(item->flags() & Qt::ItemIsEnabled))
|
|---|
| 89 | return;
|
|---|
| 90 |
|
|---|
| 91 | if (item->checkState() == CurItemCheckState)
|
|---|
| 92 | {
|
|---|
| 93 | //Clicked on the list item (not checkbox)
|
|---|
| 94 | if (item->checkState() == Qt::Checked)
|
|---|
| 95 | {
|
|---|
| 96 | item->setCheckState(Qt::Unchecked);
|
|---|
| 97 | }
|
|---|
| 98 | else
|
|---|
| 99 | item->setCheckState(Qt::Checked);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | //else - clicked on the checkbox itself, do nothing
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | void PrefAssociations::listItemPressed(QListWidgetItem* item)
|
|---|
| 106 | {
|
|---|
| 107 | CurItemCheckState = item->checkState();
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | void PrefAssociations::addItem(QString label)
|
|---|
| 111 | {
|
|---|
| 112 | QListWidgetItem* item = new QListWidgetItem(listWidget);
|
|---|
| 113 | item->setText(label);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | void PrefAssociations::refreshList()
|
|---|
| 117 | {
|
|---|
| 118 | m_regExtensions.clear();
|
|---|
| 119 | WinFileAssoc ().GetRegisteredExtensions(Extensions().multimedia(), m_regExtensions);
|
|---|
| 120 |
|
|---|
| 121 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 122 | {
|
|---|
| 123 | QListWidgetItem* pItem = listWidget->item(k);
|
|---|
| 124 | if (pItem)
|
|---|
| 125 | {
|
|---|
| 126 | pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
|---|
| 127 |
|
|---|
| 128 | if (m_regExtensions.contains(pItem->text()))
|
|---|
| 129 | {
|
|---|
| 130 | pItem->setCheckState(Qt::Checked);
|
|---|
| 131 | //Don't allow de-selection in windows VISTA if extension is registered.
|
|---|
| 132 | //VISTA doesn't seem to support extension 'restoration' in the API.
|
|---|
| 133 | if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) {
|
|---|
| 134 | pItem->setFlags(0);
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 | else
|
|---|
| 138 | {
|
|---|
| 139 | pItem->setCheckState(Qt::Unchecked);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | void PrefAssociations::setData(Preferences * )
|
|---|
| 147 | {
|
|---|
| 148 | refreshList();
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | int PrefAssociations::ProcessAssociations(QStringList& current, QStringList& old)
|
|---|
| 152 | {
|
|---|
| 153 | WinFileAssoc RegAssoc;
|
|---|
| 154 |
|
|---|
| 155 | QStringList toRestore;
|
|---|
| 156 |
|
|---|
| 157 | //Restore unselected associations
|
|---|
| 158 | foreach(const QString& ext, old)
|
|---|
| 159 | {
|
|---|
| 160 | if (!current.contains(ext))
|
|---|
| 161 | toRestore.append(ext);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | RegAssoc.RestoreFileAssociations(toRestore);
|
|---|
| 165 | return RegAssoc.CreateFileAssociations(current);
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | void PrefAssociations::getData(Preferences *)
|
|---|
| 169 | {
|
|---|
| 170 | QStringList extensions;
|
|---|
| 171 |
|
|---|
| 172 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 173 | {
|
|---|
| 174 | QListWidgetItem* pItem = listWidget->item(k);
|
|---|
| 175 | if (pItem && pItem->checkState() == Qt::Checked)
|
|---|
| 176 | extensions.append(pItem->text());
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | int processed = ProcessAssociations(extensions, m_regExtensions);
|
|---|
| 180 |
|
|---|
| 181 | if (processed != extensions.count())
|
|---|
| 182 | {
|
|---|
| 183 | QMessageBox::warning(this, tr("Warning"),
|
|---|
| 184 | tr("Not all files could be associated. Please check your "
|
|---|
| 185 | "security permissions and retry."), QMessageBox::Ok);
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | refreshList(); //Useless when OK is pressed... How to detect if apply or ok is pressed ?
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | QString PrefAssociations::sectionName() {
|
|---|
| 192 | return tr("File Types");
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | QPixmap PrefAssociations::sectionIcon() {
|
|---|
| 196 | return Images::icon("pref_associations");
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | void PrefAssociations::retranslateStrings() {
|
|---|
| 200 |
|
|---|
| 201 | retranslateUi(this);
|
|---|
| 202 | createHelp();
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | void PrefAssociations::createHelp() {
|
|---|
| 206 |
|
|---|
| 207 | clearHelp();
|
|---|
| 208 |
|
|---|
| 209 | setWhatsThis(selectAll, tr("Select all"),
|
|---|
| 210 | tr("Check all file types in the list"));
|
|---|
| 211 |
|
|---|
| 212 | setWhatsThis(selectNone, tr("Select none"),
|
|---|
| 213 | tr("Uncheck all file types in the list"));
|
|---|
| 214 |
|
|---|
| 215 | setWhatsThis(listWidget, tr("List of file types"),
|
|---|
| 216 | tr("Check the media file extensions you would like SMPlayer to handle. "
|
|---|
| 217 | "When you click Apply, the checked files will be associated with "
|
|---|
| 218 | "SMPlayer. If you uncheck a media type, the file association will "
|
|---|
| 219 | "be restored.") +
|
|---|
| 220 | tr(" <b>Note:</b> (Restoration doesn't work on Windows Vista)."));
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | #include "moc_prefassociations.cpp"
|
|---|
| 224 |
|
|---|