1
1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2007 Ricardo Villalba <rvm@escomposlinux.org>
2
Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
4
4
This program is free software; you can redistribute it and/or modify
5
5
it under the terms of the GNU General Public License as published by
43
43
connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(listItemClicked(QListWidgetItem*)));
44
44
connect(listWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(listItemPressed(QListWidgetItem*)));
47
if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA)
49
//Hide Select None - One cannot restore an association in Vista. Go figure.
51
//QPushButton* lpbButton = new QPushButton("Launch Program Defaults", this);
52
//hboxLayout->addWidget(lpbButton);
53
//connect(lpbButton, SIGNAL(clicked(bool)), this, SLOT(launchAppDefaults()));
98
for (int n=0; n < e.video().count(); n++) {
99
addItem( e.video()[n] );
101
for (int n=0; n < e.audio().count(); n++) {
102
if (e.audio()[n] != "ogg") // Already in video
103
addItem( e.audio()[n] );
58
for (int n=0; n < e.multimedia().count(); n++) {
59
addItem( e.multimedia()[n] );
106
62
retranslateStrings();
128
85
void PrefAssociations::listItemClicked(QListWidgetItem* item)
87
if (!(item->flags() & Qt::ItemIsEnabled))
130
90
if (item->checkState() == CurItemCheckState)
132
92
//Clicked on the list item (not checkbox)
133
93
if (item->checkState() == Qt::Checked)
134
95
item->setCheckState(Qt::Unchecked);
136
98
item->setCheckState(Qt::Checked);
138
101
//else - clicked on the checkbox itself, do nothing
148
111
QListWidgetItem* item = new QListWidgetItem(listWidget);
149
112
item->setText(label);
150
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
153
void PrefAssociations::setData(Preferences * pref)
115
void PrefAssociations::refreshList()
155
QStringList extensions = pref->extensions.split(",");
117
m_regExtensions.clear();
118
WinFileAssoc ().GetRegisteredExtensions(Extensions().multimedia(), m_regExtensions);
156
120
for (int k = 0; k < listWidget->count(); k++)
158
122
QListWidgetItem* pItem = listWidget->item(k);
161
//pItem->setSelected(extensions.contains(pItem->text()));
162
if (extensions.contains(pItem->text()))
125
pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
127
if (m_regExtensions.contains(pItem->text()))
163
129
pItem->setCheckState(Qt::Checked);
130
//Don't allow de-selection in windows VISTA if extension is registered.
131
//VISTA doesn't seem to support extension 'restoration' in the API.
133
if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA) {
165
140
pItem->setCheckState(Qt::Unchecked);
147
void PrefAssociations::setData(Preferences * )
171
152
int PrefAssociations::ProcessAssociations(QStringList& current, QStringList& old)
154
WinFileAssoc RegAssoc;
175
WinFileAssoc RegAssoc("MPlayerFileVideo");
156
QStringList toRestore;
177
158
//Restore unselected associations
178
for (int k = 0; k < old.count(); k++)
159
foreach(const QString& ext, old)
180
const QString& ext = old[k];
181
161
if (!current.contains(ext))
183
RegAssoc.RestoreFileAssociation(ext);
187
//Set current associations
188
if (current.count() > 0)
190
RegAssoc.CreateClassId(QApplication::applicationFilePath(), "MPlayer Video File");
192
for (int k = 0; k < current.count(); k++)
194
if (RegAssoc.CreateFileAssociation(current[k]))
199
RegAssoc.RemoveClassId();
162
toRestore.append(ext);
165
RegAssoc.RestoreFileAssociations(toRestore);
166
return RegAssoc.CreateFileAssociations(current);
204
void PrefAssociations::getData(Preferences * pref)
169
void PrefAssociations::getData(Preferences *)
206
171
QStringList extensions;
212
177
extensions.append(pItem->text());
215
QStringList old = pref->extensions.split(",");
217
int processed = ProcessAssociations(extensions, old);
219
//Save the new associations
220
pref->extensions = extensions.join(",");
180
int processed = ProcessAssociations(extensions, m_regExtensions);
222
182
if (processed != extensions.count())
225
185
tr("Not all files could be associated. Please check your "
226
186
"security permissions and retry."), QMessageBox::Ok);
189
refreshList(); //Useless when OK is pressed... How to detect if apply or ok is pressed ?
231
192
QString PrefAssociations::sectionName() {
239
200
void PrefAssociations::retranslateStrings() {
240
202
retranslateUi(this);
244
void PrefAssociations::createHelp()
206
void PrefAssociations::createHelp() {
248
210
setWhatsThis(selectAll, tr("Select all"),
255
217
tr("Check the media file extensions you would like SMPlayer to handle. "
256
218
"When you click Apply, the checked files will be associated with "
257
219
"SMPlayer. If you uncheck a media type, the file association will "
221
tr(" <b>Note:</b> (Restoration doesn't work on Windows Vista)."));
261
224
#include "moc_prefassociations.cpp"