source: smplayer/trunk/src/prefassociations.cpp@ 181

Last change on this file since 181 was 181, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.8.0

  • Property svn:eol-style set to LF
File size: 6.4 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 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#if QT_VERSION >= 0x050000
34#include "myscroller.h"
35#endif
36
37static Qt::CheckState CurItemCheckState = Qt::Unchecked;
38
39
40PrefAssociations::PrefAssociations(QWidget * parent, Qt::WindowFlags f)
41: PrefWidget(parent, f )
42{
43 setupUi(this);
44
45#if QT_VERSION >= 0x050000
46 MyScroller::setScroller(listWidget->viewport());
47#endif
48
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();
72
73 something_changed = false;
74}
75
76PrefAssociations::~PrefAssociations()
77{
78
79}
80
81void PrefAssociations::selectAllClicked(bool)
82{
83 for (int k = 0; k < listWidget->count(); k++)
84 listWidget->item(k)->setCheckState(Qt::Checked);
85 listWidget->setFocus();
86
87 something_changed = true;
88}
89
90void PrefAssociations::selectNoneClicked(bool)
91{
92
93 for (int k = 0; k < listWidget->count(); k++)
94 listWidget->item(k)->setCheckState(Qt::Unchecked);
95 listWidget->setFocus();
96
97 something_changed = true;
98}
99
100void PrefAssociations::listItemClicked(QListWidgetItem* item)
101{
102 qDebug("PrefAssociations::listItemClicked");
103
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
119
120 something_changed = true;
121}
122
123void PrefAssociations::listItemPressed(QListWidgetItem* item)
124{
125 CurItemCheckState = item->checkState();
126}
127
128void PrefAssociations::addItem(QString label)
129{
130 QListWidgetItem* item = new QListWidgetItem(listWidget);
131 item->setText(label);
132}
133
134void 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
164void PrefAssociations::setData(Preferences * )
165{
166 refreshList();
167}
168
169int 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
186void PrefAssociations::getData(Preferences *)
187{
188 qDebug("PrefAssociations::getData: something_changed: %d", something_changed);
189 if (!something_changed) return;
190
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 ?
210
211 something_changed = false;
212}
213
214QString PrefAssociations::sectionName() {
215 return tr("File Types");
216}
217
218QPixmap PrefAssociations::sectionIcon() {
219 return Images::icon("pref_associations");
220}
221
222void PrefAssociations::retranslateStrings() {
223
224 retranslateUi(this);
225 createHelp();
226}
227
228void 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 "
242 "be restored.") + "<br><b>" + tr("Note:") + "</b> " +
243 tr("Restoration doesn't work on Windows Vista."));
244}
245
246#include "moc_prefassociations.cpp"
247
Note: See TracBrowser for help on using the repository browser.