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