~ubuntu-branches/debian/sid/smplayer/sid

« back to all changes in this revision

Viewing changes to src/prefassociations.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2008-01-31 13:44:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080131134453-nc4dwsn5pkiw5s9h
Tags: 0.6.0~rc1-1
* New upstream release.
* debian/control:
  - Build-depend on CDBS.
  - Updated upstream homepage.
* debian/copyright:
  - Updated download address.
* debian/rules:
  - Migrated to CDBS.
  - Tweaked get-orig-source to work with release candidates.
* debian/docs:
  - Removed Translations.txt, upstream removed it from the tarball.
  - Added Release_notes.txt.
* debian/manpages, debian/smplayer.1:
  - Deleted, manpage merged upstream.
* debian/smplayer.install:
  - Install usr/share/man.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
3
3
 
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
24
24
 
25
25
#include "prefassociations.h"
26
26
#include "images.h"
27
 
#include "preferences.h"
28
27
#include <QSettings>
29
28
#include <QApplication>
30
29
#include <QMessageBox>
33
32
 
34
33
static Qt::CheckState CurItemCheckState = Qt::Unchecked; 
35
34
 
 
35
 
36
36
PrefAssociations::PrefAssociations(QWidget * parent, Qt::WindowFlags f)
37
37
: PrefWidget(parent, f )
38
38
{
43
43
        connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(listItemClicked(QListWidgetItem*))); 
44
44
        connect(listWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(listItemPressed(QListWidgetItem*))); 
45
45
 
46
 
        /*
47
 
        //Video for windows
48
 
        addItem("avi");
49
 
        addItem("vfw");
50
 
        addItem("divx");
51
 
 
52
 
        //MPEG
53
 
        addItem("mpg");
54
 
        addItem("mpeg");
55
 
        addItem("m1v");
56
 
        addItem("m2v");
57
 
        addItem("mpv");
58
 
        addItem("dv");
59
 
        addItem("3gp");
60
 
 
61
 
        //QT
62
 
        addItem("mov");
63
 
        addItem("mp4");
64
 
        addItem("m4v");
65
 
        addItem("mqv");
66
 
 
67
 
        //VCD
68
 
        addItem("dat");
69
 
        addItem("vcd");
70
 
 
71
 
        //OGG
72
 
        addItem("ogg");
73
 
        addItem("ogm");
74
 
 
75
 
        //WMV
76
 
        addItem("asf");
77
 
        addItem("wmv");
78
 
 
79
 
        //Matroska
80
 
        addItem("mkv");
81
 
 
82
 
        //NSV
83
 
        addItem("nsv"); 
84
 
 
85
 
        //REAL
86
 
        addItem("ram"); 
87
 
 
88
 
        //DVD
89
 
        addItem("bin");
90
 
        addItem("iso");
91
 
        addItem("vob"); 
92
 
 
93
 
        //FLV
94
 
        addItem("flv");
95
 
        */
 
46
#ifdef Q_OS_WIN
 
47
        if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA)
 
48
        {
 
49
                //Hide Select None - One cannot restore an association in Vista. Go figure.
 
50
                selectNone->hide(); 
 
51
                //QPushButton* lpbButton = new QPushButton("Launch Program Defaults", this); 
 
52
                //hboxLayout->addWidget(lpbButton); 
 
53
                //connect(lpbButton, SIGNAL(clicked(bool)), this, SLOT(launchAppDefaults()));
 
54
        }
 
55
#endif
96
56
 
97
57
        Extensions e;
98
 
        for (int n=0; n < e.video().count(); n++) {
99
 
                addItem( e.video()[n] );
100
 
        }
101
 
        for (int n=0; n < e.audio().count(); n++) {
102
 
                if (e.audio()[n] != "ogg") // Already in video
103
 
                        addItem( e.audio()[n] );
104
 
        }
105
 
        
 
58
        for (int n=0; n < e.multimedia().count(); n++) {
 
59
                addItem( e.multimedia()[n] );
 
60
        }
 
61
 
106
62
        retranslateStrings();
107
63
}
108
64
 
120
76
 
121
77
void PrefAssociations::selectNoneClicked(bool)
122
78
{
 
79
 
123
80
        for (int k = 0; k < listWidget->count(); k++)
124
81
                listWidget->item(k)->setCheckState(Qt::Unchecked);
125
82
        listWidget->setFocus(); 
127
84
 
128
85
void PrefAssociations::listItemClicked(QListWidgetItem* item)
129
86
{
 
87
        if (!(item->flags() & Qt::ItemIsEnabled))
 
88
                return; 
 
89
 
130
90
        if (item->checkState() == CurItemCheckState)
131
91
        {
132
92
                //Clicked on the list item (not checkbox)
133
93
                if (item->checkState() == Qt::Checked)
 
94
                {
134
95
                        item->setCheckState(Qt::Unchecked);
 
96
                }
135
97
                else
136
98
                        item->setCheckState(Qt::Checked); 
137
99
        }
 
100
 
138
101
        //else - clicked on the checkbox itself, do nothing
139
102
}
140
103
 
147
110
{
148
111
        QListWidgetItem* item = new QListWidgetItem(listWidget); 
149
112
        item->setText(label);
150
 
        item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
151
113
}
152
114
 
153
 
void PrefAssociations::setData(Preferences * pref)
 
115
void PrefAssociations::refreshList()
154
116
{
155
 
        QStringList extensions = pref->extensions.split(",");
 
117
        m_regExtensions.clear(); 
 
118
        WinFileAssoc ().GetRegisteredExtensions(Extensions().multimedia(), m_regExtensions); 
 
119
 
156
120
        for (int k = 0; k < listWidget->count(); k++)
157
121
        {
158
122
                QListWidgetItem* pItem = listWidget->item(k); 
159
123
                if (pItem)
160
124
                {
161
 
                        //pItem->setSelected(extensions.contains(pItem->text()));
162
 
                        if (extensions.contains(pItem->text()))
 
125
                        pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
 
126
 
 
127
                        if (m_regExtensions.contains(pItem->text()))
 
128
                        {
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.
 
132
#ifdef Q_OS_WIN
 
133
                                if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA) {
 
134
                                        pItem->setFlags(0);
 
135
                                }
 
136
#endif
 
137
                        }
164
138
                        else
 
139
                        {
165
140
                                pItem->setCheckState(Qt::Unchecked);
 
141
                        }
166
142
 
167
143
                }
168
144
        }
169
145
}
170
146
 
 
147
void PrefAssociations::setData(Preferences * )
 
148
{
 
149
        refreshList(); 
 
150
}
 
151
 
171
152
int PrefAssociations::ProcessAssociations(QStringList& current, QStringList& old)
172
153
{
173
 
        int processed = 0; 
 
154
        WinFileAssoc RegAssoc; 
174
155
 
175
 
        WinFileAssoc RegAssoc("MPlayerFileVideo"); 
 
156
        QStringList toRestore; 
176
157
 
177
158
        //Restore unselected associations
178
 
        for (int k = 0; k < old.count(); k++)
 
159
        foreach(const QString& ext, old)
179
160
        {
180
 
                const QString& ext = old[k];
181
161
                if (!current.contains(ext))
182
 
                {
183
 
                        RegAssoc.RestoreFileAssociation(ext);
184
 
                }
185
 
        }
186
 
        
187
 
        //Set current associations
188
 
        if (current.count() > 0)
189
 
        {
190
 
                RegAssoc.CreateClassId(QApplication::applicationFilePath(), "MPlayer Video File");
191
 
 
192
 
                for (int k = 0; k < current.count(); k++)
193
 
                {
194
 
                        if (RegAssoc.CreateFileAssociation(current[k]))
195
 
                                processed++; 
196
 
                }
197
 
        }
198
 
        else
199
 
                RegAssoc.RemoveClassId();  
200
 
 
201
 
        return processed; 
 
162
                        toRestore.append(ext); 
 
163
        }
 
164
 
 
165
        RegAssoc.RestoreFileAssociations(toRestore); 
 
166
        return RegAssoc.CreateFileAssociations(current); 
202
167
}
203
168
 
204
 
void PrefAssociations::getData(Preferences * pref)
 
169
void PrefAssociations::getData(Preferences *)
205
170
{
206
171
        QStringList extensions; 
207
172
 
212
177
                        extensions.append(pItem->text()); 
213
178
        }
214
179
 
215
 
        QStringList old = pref->extensions.split(","); 
216
 
 
217
 
        int processed = ProcessAssociations(extensions, old); 
218
 
 
219
 
        //Save the new associations
220
 
        pref->extensions = extensions.join(","); 
 
180
        int processed = ProcessAssociations(extensions, m_regExtensions); 
221
181
 
222
182
        if (processed != extensions.count())
223
183
        {
225
185
            tr("Not all files could be associated. Please check your "
226
186
               "security permissions and retry."), QMessageBox::Ok);
227
187
        }
228
 
 
 
188
        
 
189
        refreshList(); //Useless when OK is pressed... How to detect if apply or ok is pressed ?
229
190
}
230
191
 
231
192
QString PrefAssociations::sectionName() {
237
198
}
238
199
 
239
200
void PrefAssociations::retranslateStrings() {
 
201
 
240
202
        retranslateUi(this);
241
203
        createHelp();
242
204
}
243
205
 
244
 
void PrefAssociations::createHelp()
245
 
{
 
206
void PrefAssociations::createHelp() {
 
207
 
246
208
        clearHelp();
247
209
 
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 "
258
 
                   "be restored."));
 
220
                   "be restored.") +
 
221
        tr(" <b>Note:</b> (Restoration doesn't work on Windows Vista)."));
259
222
}
260
223
 
261
224
#include "moc_prefassociations.cpp"