This repository has been archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
DockInputOutput.cpp
446 lines (377 loc) · 13.9 KB
/
DockInputOutput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/***************************************************************************//**
* @brief Thumbnail me 3.0
* Thumbnail me is a user interface for Movie thumbnailer.
* Generate thumbnails from any movie is now easier !
*
* @file DockInputOutput.cpp
* @class DockInputOutput
* Cette classe permet la génération du dock "Entrée et sortie".
*
* @author Quentin Rousseau\n
* @note Copyright (C) 2011-2012 Quentin Rousseau\n
* License: GNU General Public License version 2 (GPLv2) - http://www.gnu.org/licenses/gpl-2.0.html\n
* Site web: www.thumbnailme.com\n
* Email: [email protected]
*
* @since 3.0
* @version 3.0
* @date 2011-2012
*
* @changelog 25/09/2011 - Destination Folder Editable.
*******************************************************************************/
#include "DockInputOutput.h"
#include "defines.h"
#include "DockTimeLine.h"
#include "MainWindow.h"
#include "ThumbnailListWidget.h"
#include "ThumbnailItem.h"
#include "ThumbnailEngine.h"
#include <QGridLayout>
#include <QPushButton>
#include <QFileDialog>
#include "QtHelper.h"
/**
*@brief Constructeur.
*@param *main_window Fenêtre principale de Thumbnail me.
*@param *thumbnailEngine Moteur de transformation.
*/
DockInputOutput::DockInputOutput(MainWindow *main_window, ThumbnailEngine *thumbnailEngine) : QDockWidget(main_window)
{
this->main_window = main_window;
settings = new QSettings(QSettings::IniFormat,DEFAULT_PATH_INI,APPLICATION_NAME,DEFAULT_FILE_INI,this);
this->setObjectName("inputoutputDock");
this->setAcceptDrops(true);
this->setFeatures(QDockWidget::DockWidgetMovable);
thumbnailListWidget = new ThumbnailListWidget(this);
QGridLayout *batchmodLayout = new QGridLayout;
loadButton = new QPushButton(QIcon(":/sprites/openfolder.png"),QString());
resetListButton = new QPushButton(QIcon(":/sprites/recycle-bin-full.png"),QString());
resetListButton->setDisabled(true);
runBatchButton = new QPushButton(QIcon(":/sprites/run.png"),QString());
runBatchButton->setDisabled(true);
deleteSelectionButton = new QPushButton(QIcon(":/sprites/recycle-bin-full.png"),QString());
deleteSelectionButton->setDisabled(true);
pathOutputLabel = new QLabel(tr("Path Output")+":");
previewSelectionButton = new QPushButton(QIcon(":/sprites/preview.png"),QString());
previewSelectionButton->setDisabled(true);
outputButton = new QPushButton(QIcon(":/sprites/openfolder.png"),"...");
arrowUpButton = new QPushButton(QIcon(":/sprites/arrow_up.png"),QString());
arrowDownButton = new QPushButton(QIcon(":/sprites/arrow_down.png"),QString());
arrowUpButton->setDisabled(true);
arrowDownButton->setDisabled(true);
pathOutput = new QLineEdit(this);
sameSourceCheckBox = new QCheckBox(tr("Same folder output as source"));
QGridLayout * batchModMiddleLayout = new QGridLayout;
QGridLayout * batchModRightLayout = new QGridLayout;
QVBoxLayout * arrowsLayout = new QVBoxLayout;
arrowsLayout->addWidget(arrowUpButton);
arrowsLayout->addWidget(arrowDownButton);
batchmodLayout->addLayout(arrowsLayout,0,3);
batchmodLayout->addWidget( thumbnailListWidget,0,2);
batchmodLayout->setColumnStretch(2,2);
batchModMiddleLayout->addWidget( loadButton,0,0 );
batchModMiddleLayout->addWidget( deleteSelectionButton,1,0);
batchModMiddleLayout->addWidget( resetListButton,2,0);
batchModRightLayout->addWidget( sameSourceCheckBox,0,1,Qt::AlignHCenter);
batchModRightLayout->addWidget( pathOutputLabel,1,0);
batchModRightLayout->addWidget( pathOutput,1,1);
batchModRightLayout->addWidget( outputButton,1,2);
batchModRightLayout->addWidget( previewSelectionButton,2,1);
batchModRightLayout->addWidget( runBatchButton,3,1);
batchmodLayout->addLayout(batchModMiddleLayout,0,1);
batchmodLayout->addWidget(QtHelper::addVSeparator(),0,4);
batchmodLayout->addLayout(batchModRightLayout,0,5);
contentWidget = new QWidget(this);
contentWidget->setLayout(batchmodLayout);
/*Connections*/
connect( loadButton, SIGNAL(clicked()), this, SLOT(loadList()) );
connect( resetListButton, SIGNAL(clicked()), this, SLOT(resetListWidget()) );
connect( deleteSelectionButton, SIGNAL(clicked()), this, SLOT(removeItemSelection()) );
connect( outputButton, SIGNAL(clicked()), this, SLOT(openFileDialogPathOutput()) );
connect( arrowUpButton, SIGNAL(clicked()), this, SLOT(moveItemUp()) );
connect( arrowDownButton, SIGNAL(clicked()), this, SLOT(moveItemDown()) );
connect( sameSourceCheckBox, SIGNAL(stateChanged(int)), this, SLOT(disablePathOutput(int)) );
connect( thumbnailListWidget, SIGNAL(itemClicked ( QListWidgetItem *)), main_window->mpDockTimeline, SLOT(update( QListWidgetItem * )) );
connect( thumbnailListWidget, SIGNAL(itemClicked ( QListWidgetItem *)), this, SLOT(arrowsManager( QListWidgetItem * )) );
connect( thumbnailListWidget, SIGNAL(itemSelectionChanged ()), this, SLOT(enableRemoveSelectionButton()) );
connect( thumbnailListWidget, SIGNAL(currentRowChanged ( int )), this, SLOT(enableResetButton( int )) );
connect( thumbnailListWidget, SIGNAL(itemDeleted ()), this, SLOT(removeItemSelection()) );
QSignalMapper *signalMapper = new QSignalMapper(this);
signalMapper->setMapping(runBatchButton,SIMPLE);
signalMapper->setMapping(previewSelectionButton,PREVIEW);
connect( signalMapper, SIGNAL(mapped(int)), thumbnailEngine, SLOT(run(int)) );
connect( runBatchButton, SIGNAL(clicked ()), signalMapper, SLOT(map()) );
connect( previewSelectionButton,SIGNAL(clicked ()), signalMapper, SLOT(map()) );
//Par défaut sameSourceCheckBox cochée.
sameSourceCheckBox->setChecked(true);
this->setWidget( contentWidget );
this->retranslate();
}
/**
*@brief Destructeur.
*/
DockInputOutput::~DockInputOutput()
{
}
/**
*@brief Retourne la QListWidget propre au Dock.
*@return QListWidget* - Pointeur sur la QListWidget du Dock.
*/
ThumbnailListWidget *DockInputOutput::getListWidget()
{
return thumbnailListWidget;
}
/**
*@brief Retourne la liste complête des items du QListWidget.
*@return QStringList - Liste des chemins contenus dans la QListWidget.
*/
QStringList DockInputOutput::getAllItemListWidget()
{
return QtHelper::getItemsListWidget(getListWidget());
}
/**
*@brief Retourne les chemins des dossiers des items du QListWidget.
*@return QStringList - Liste des chemins.
*/
QStringList DockInputOutput::getAllItemListCanonicalPath()
{
QStringList canonicalPathStringList;
foreach(QString item,getAllItemListWidget())
{
canonicalPathStringList << QDir::toNativeSeparators(QFileInfo(item).canonicalPath());
}
return canonicalPathStringList;
}
/**
*@brief Retourne le dernier path du QListWidget.
*@return QString - Retourne dernier chemin de la QListWidget.
*/
QString DockInputOutput::getLastItemListWidget()
{
return getListWidget()->item(getListWidget()->count()-1)->text();
}
/**
*@brief Retourne le chemin de sortie.
*@return QString - Retourne le chemin de sortie.
*/
QString DockInputOutput::getPathOutput()
{
return pathOutput->displayText();
}
/**
*@brief Retourne le ThumbnailItem sélectionné.
*@return ThumbnailItem* - ThumbnailItem.
*/
ThumbnailItem* DockInputOutput::getCurrentItem()
{
return static_cast<ThumbnailItem*> (this->thumbnailListWidget->currentItem());
}
/**
*@brief Setteur du chemin du dossier de sortie.
*@param filePath Chemin de sortie.
*/
void DockInputOutput::setPathOutput(QString filePath)
{
if (!filePath.isEmpty())
{
settings->setValue("last_path_output_batchmod",filePath);
pathOutput->setText(filePath);
}
}
/**
*@brief Appelle la fenêtre d'exploration pour parcourir les fichiers à charger.
*/
void DockInputOutput::loadList()
{
QStringList files;
if (settings->value("last_path_input_batchmod").toString() != "undefined")
files = QFileDialog::getOpenFileNames(this,"",settings->value("last_path_input_batchmod").toString(),"Video Files (*.avi *.mkv *.ts *.m2ts *.mpeg *.mpg *.mp4 *.m4v *.ogg *.wmv *.3gp *.dat *.mov *.vob *.flv *.swf)");
else
files = QFileDialog::getOpenFileNames(this,"","","Video Files (*.avi *.mkv *.ts *.m2ts *.mpeg *.mpg *.mp4 *.m4v *.ogg *.wmv *.3gp *.dat *.mov *.vob *.flv *.swf)");
if (!files.isEmpty())
{
QFileInfo fileInfo(files[0]);
settings->setValue("last_path_input_batchmod",fileInfo.absolutePath());
arrowUpButton->setDisabled(true);
arrowDownButton->setEnabled(true);
thumbnailListWidget->addItems(files);
}
}
/**
*@brief Appelle la fenêtre d'exploration pour parcourir le dossier de sortie.
*/
void DockInputOutput::openFileDialogPathOutput()
{
QString path;
if (settings->value("last_path_output_batchmod").toString() != "undefined")
path = QFileDialog::getExistingDirectory(this,"",settings->value("last_path_output_batchmod").toString());
else
path = QFileDialog::getExistingDirectory();
this->setPathOutput(QDir::toNativeSeparators(path));
}
/**
*@brief ChangeEvent.
*@param *event Evenement.
*/
void DockInputOutput::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
retranslate();
QDockWidget::changeEvent(event);
}
/**
*@brief Supprime les items sélectionnés
*/
void DockInputOutput::removeItemSelection()
{
thumbnailListWidget->removeItemSelection();
main_window->mpDockTimeline->clear();
}
/**
*@brief CheckBox "Same Folder output as source" checked?
*@return Vrai ou faux.
*/
bool DockInputOutput::isSameSourceChecked()
{
return sameSourceCheckBox->isChecked();
}
/**
*@brief Setter de "Same Folder output as source".
*@param state Etat de la checkBox.
*/
void DockInputOutput::setSameSourceChecked(bool state)
{
sameSourceCheckBox->setChecked(state);
}
/**
*@brief CheckBox "Same Folder output as source" checked?
*@param state Etat de la checkBox.
*/
void DockInputOutput::disablePathOutput(int state)
{
bool localState = (state == Qt::Checked) ? true : false;
if(localState)
{
pathOutputLabel->setDisabled(localState);
pathOutput->setDisabled(localState);
outputButton->setDisabled(localState);
}
else
{
pathOutputLabel->setDisabled(localState);
pathOutput->setDisabled(localState);
outputButton->setDisabled(localState);
}
}
/**
*@brief Déplace un item vers le haut.
*/
void DockInputOutput::moveItemUp()
{
int currentRow = thumbnailListWidget->currentRow();
if (currentRow == 1)
arrowUpButton->setDisabled(true);
else
arrowUpButton->setDisabled(false);
arrowDownButton->setEnabled(true);
QListWidgetItem * currentItem = thumbnailListWidget->takeItem(currentRow);
thumbnailListWidget->insertItem(currentRow - 1, currentItem);
thumbnailListWidget->setCurrentRow(currentRow - 1);
}
/**
*@brief Déplace un item vers le haut.
*/
void DockInputOutput::moveItemDown()
{
int currentRow = thumbnailListWidget->currentRow();
if (currentRow == thumbnailListWidget->count() - 2 )
arrowDownButton->setDisabled(true);
else arrowDownButton->setDisabled(false);
arrowUpButton->setEnabled(true);
QListWidgetItem * currentItem = thumbnailListWidget->takeItem(currentRow);
thumbnailListWidget->insertItem(currentRow + 1, currentItem);
thumbnailListWidget->setCurrentRow(currentRow + 1);
}
/**
*@brief Enable ou Disable les flèches en fonction de l'item selectionné.
*@param item Item selectionné.
*/
void DockInputOutput::arrowsManager(QListWidgetItem *item)
{
if(item == thumbnailListWidget->item(0))
arrowUpButton->setDisabled(true);
else arrowUpButton->setEnabled(true);
if(item == thumbnailListWidget->item(thumbnailListWidget->count() - 1))
arrowDownButton->setDisabled(true);
else arrowDownButton->setEnabled(true);
}
/**
*@brief Réinitialise la liste des médias.
*/
void DockInputOutput::resetListWidget()
{
if(thumbnailListWidget->count() != 0)
{
thumbnailListWidget->clear();
arrowUpButton->setDisabled(true);
arrowDownButton->setDisabled(true);
main_window->mpDockTimeline->clear();
}
else QMessageBox::information(this, _ERROR_, tr("Media list is already empty"));
}
/**
*@brief Enable or Disabled le bouton reset en fonction du nombre d'item présent dans la liste.
*@param row Colonne de l'item courant.
*/
void DockInputOutput::enableResetButton(int row)
{
//If there is no current item, the currentRow is -1.
if(row == -1)
{
resetListButton->setDisabled(true);
runBatchButton->setDisabled(true);
}
else
{
resetListButton->setDisabled(false);
runBatchButton->setDisabled(false);
}
}
/**
*@brief Enable or Disabled le bouton Remove Selection si un item est sélectionné ou non.
*/
void DockInputOutput::enableRemoveSelectionButton()
{
if(thumbnailListWidget->selectedItems().isEmpty())
{
deleteSelectionButton->setDisabled(true);
previewSelectionButton->setDisabled(true);
}
else
{
deleteSelectionButton->setDisabled(false);
previewSelectionButton->setDisabled(false);
}
}
/**
*@brief Retourne la liste contenant les images à convertir.
*@return QLinkedList <ThumbnailItem*> - Liste.
*/
QLinkedList <ThumbnailItem*> DockInputOutput::getThumbnailList()
{
return getListWidget()->getItemsListWidget();
}
/**
*@brief Fonction de traduction dynamique.
*/
void DockInputOutput::retranslate()
{
this->setWindowTitle( tr("Input and Output") );
loadButton->setText( tr("Load") );
resetListButton->setText( tr("Reset") );
runBatchButton->setText( tr("Start") );
deleteSelectionButton->setText( tr("Delete Selection") );
pathOutputLabel->setText( tr("Path Output") + " :" );
previewSelectionButton->setText( tr("Preview selection file") );
sameSourceCheckBox->setText( tr("Same folder output as source") );
}