| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net>
|
|---|
| 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 | something_changed = false;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | PrefAssociations::~PrefAssociations()
|
|---|
| 69 | {
|
|---|
| 70 |
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | void PrefAssociations::selectAllClicked(bool)
|
|---|
| 74 | {
|
|---|
| 75 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 76 | listWidget->item(k)->setCheckState(Qt::Checked);
|
|---|
| 77 | listWidget->setFocus();
|
|---|
| 78 |
|
|---|
| 79 | something_changed = true;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | void PrefAssociations::selectNoneClicked(bool)
|
|---|
| 83 | {
|
|---|
| 84 |
|
|---|
| 85 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 86 | listWidget->item(k)->setCheckState(Qt::Unchecked);
|
|---|
| 87 | listWidget->setFocus();
|
|---|
| 88 |
|
|---|
| 89 | something_changed = true;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | void PrefAssociations::listItemClicked(QListWidgetItem* item)
|
|---|
| 93 | {
|
|---|
| 94 | qDebug("PrefAssociations::listItemClicked");
|
|---|
| 95 |
|
|---|
| 96 | if (!(item->flags() & Qt::ItemIsEnabled))
|
|---|
| 97 | return;
|
|---|
| 98 |
|
|---|
| 99 | if (item->checkState() == CurItemCheckState)
|
|---|
| 100 | {
|
|---|
| 101 | //Clicked on the list item (not checkbox)
|
|---|
| 102 | if (item->checkState() == Qt::Checked)
|
|---|
| 103 | {
|
|---|
| 104 | item->setCheckState(Qt::Unchecked);
|
|---|
| 105 | }
|
|---|
| 106 | else
|
|---|
| 107 | item->setCheckState(Qt::Checked);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | //else - clicked on the checkbox itself, do nothing
|
|---|
| 111 |
|
|---|
| 112 | something_changed = true;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | void PrefAssociations::listItemPressed(QListWidgetItem* item)
|
|---|
| 116 | {
|
|---|
| 117 | CurItemCheckState = item->checkState();
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | void PrefAssociations::addItem(QString label)
|
|---|
| 121 | {
|
|---|
| 122 | QListWidgetItem* item = new QListWidgetItem(listWidget);
|
|---|
| 123 | item->setText(label);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | void PrefAssociations::refreshList()
|
|---|
| 127 | {
|
|---|
| 128 | m_regExtensions.clear();
|
|---|
| 129 | WinFileAssoc ().GetRegisteredExtensions(Extensions().multimedia(), m_regExtensions);
|
|---|
| 130 |
|
|---|
| 131 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 132 | {
|
|---|
| 133 | QListWidgetItem* pItem = listWidget->item(k);
|
|---|
| 134 | if (pItem)
|
|---|
| 135 | {
|
|---|
| 136 | pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
|---|
| 137 |
|
|---|
| 138 | if (m_regExtensions.contains(pItem->text()))
|
|---|
| 139 | {
|
|---|
| 140 | pItem->setCheckState(Qt::Checked);
|
|---|
| 141 | //Don't allow de-selection in windows VISTA if extension is registered.
|
|---|
| 142 | //VISTA doesn't seem to support extension 'restoration' in the API.
|
|---|
| 143 | if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) {
|
|---|
| 144 | pItem->setFlags(0);
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 | else
|
|---|
| 148 | {
|
|---|
| 149 | pItem->setCheckState(Qt::Unchecked);
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | void PrefAssociations::setData(Preferences * )
|
|---|
| 157 | {
|
|---|
| 158 | refreshList();
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | int PrefAssociations::ProcessAssociations(QStringList& current, QStringList& old)
|
|---|
| 162 | {
|
|---|
| 163 | WinFileAssoc RegAssoc;
|
|---|
| 164 |
|
|---|
| 165 | QStringList toRestore;
|
|---|
| 166 |
|
|---|
| 167 | //Restore unselected associations
|
|---|
| 168 | foreach(const QString& ext, old)
|
|---|
| 169 | {
|
|---|
| 170 | if (!current.contains(ext))
|
|---|
| 171 | toRestore.append(ext);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | RegAssoc.RestoreFileAssociations(toRestore);
|
|---|
| 175 | return RegAssoc.CreateFileAssociations(current);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | void PrefAssociations::getData(Preferences *)
|
|---|
| 179 | {
|
|---|
| 180 | qDebug("PrefAssociations::getData: something_changed: %d", something_changed);
|
|---|
| 181 | if (!something_changed) return;
|
|---|
| 182 |
|
|---|
| 183 | QStringList extensions;
|
|---|
| 184 |
|
|---|
| 185 | for (int k = 0; k < listWidget->count(); k++)
|
|---|
| 186 | {
|
|---|
| 187 | QListWidgetItem* pItem = listWidget->item(k);
|
|---|
| 188 | if (pItem && pItem->checkState() == Qt::Checked)
|
|---|
| 189 | extensions.append(pItem->text());
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | int processed = ProcessAssociations(extensions, m_regExtensions);
|
|---|
| 193 |
|
|---|
| 194 | if (processed != extensions.count())
|
|---|
| 195 | {
|
|---|
| 196 | QMessageBox::warning(this, tr("Warning"),
|
|---|
| 197 | tr("Not all files could be associated. Please check your "
|
|---|
| 198 | "security permissions and retry."), QMessageBox::Ok);
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | refreshList(); //Useless when OK is pressed... How to detect if apply or ok is pressed ?
|
|---|
| 202 |
|
|---|
| 203 | something_changed = false;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | QString PrefAssociations::sectionName() {
|
|---|
| 207 | return tr("File Types");
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | QPixmap PrefAssociations::sectionIcon() {
|
|---|
| 211 | return Images::icon("pref_associations", 22);
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | void PrefAssociations::retranslateStrings() {
|
|---|
| 215 |
|
|---|
| 216 | retranslateUi(this);
|
|---|
| 217 | createHelp();
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | void PrefAssociations::createHelp() {
|
|---|
| 221 |
|
|---|
| 222 | clearHelp();
|
|---|
| 223 |
|
|---|
| 224 | setWhatsThis(selectAll, tr("Select all"),
|
|---|
| 225 | tr("Check all file types in the list"));
|
|---|
| 226 |
|
|---|
| 227 | setWhatsThis(selectNone, tr("Select none"),
|
|---|
| 228 | tr("Uncheck all file types in the list"));
|
|---|
| 229 |
|
|---|
| 230 | setWhatsThis(listWidget, tr("List of file types"),
|
|---|
| 231 | tr("Check the media file extensions you would like SMPlayer to handle. "
|
|---|
| 232 | "When you click Apply, the checked files will be associated with "
|
|---|
| 233 | "SMPlayer. If you uncheck a media type, the file association will "
|
|---|
| 234 | "be restored.") +
|
|---|
| 235 | tr(" <b>Note:</b> (Restoration doesn't work on Windows Vista)."));
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | #include "moc_prefassociations.cpp"
|
|---|
| 239 |
|
|---|