kwave  18.07.70
FileInfoPlugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  FileInfoPlugin.cpp - plugin for editing file properties
3  -------------------
4  begin : Fri Jul 19 2002
5  copyright : (C) 2002 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 #include "errno.h"
20 
21 #include "libkwave/MessageBox.h"
22 #include "libkwave/PluginManager.h"
23 #include "libkwave/SignalManager.h"
24 #include "libkwave/String.h"
25 
26 #include "FileInfoDialog.h"
27 #include "FileInfoPlugin.h"
28 
29 KWAVE_PLUGIN(fileinfo, FileInfoPlugin)
30 
31 //***************************************************************************
33  const QVariantList &args)
34  :Kwave::Plugin(parent, args)
35 {
36 }
37 
38 //***************************************************************************
40 {
41 }
42 
43 //***************************************************************************
44 QStringList *Kwave::FileInfoPlugin::setup(QStringList &)
45 {
46  Kwave::FileInfo oldInfo(signalManager().metaData());
47 
48  // create the setup dialog
49  Kwave::FileInfoDialog *dialog =
50  new Kwave::FileInfoDialog(parentWidget(), oldInfo);
51  Q_ASSERT(dialog);
52  if (!dialog) return Q_NULLPTR;
53 
54  QStringList *list = new QStringList();
55  Q_ASSERT(list);
56  if (list && dialog->exec()) {
57  // user has pressed "OK" -> apply the new properties
58  apply(dialog->info());
59  } else {
60  // user pressed "Cancel"
61  if (list) delete list;
62  list = Q_NULLPTR;
63  }
64 
65  if (dialog) delete dialog;
66  return list;
67 }
68 
69 //***************************************************************************
71 {
72  Kwave::FileInfo old_info(signalManager().metaData());
73  if (old_info == new_info) return; // nothing to do
74 
75  /* sample rate */
76  if (!qFuzzyCompare(old_info.rate(), new_info.rate())) {
77 
78  // sample rate changed -> only change rate or resample ?
79  double new_rate = new_info.rate();
81  i18n("You have changed the sample rate. Do you want to convert "
82  "the whole file to the new sample rate or do "
83  "you only want to set the rate information in order "
84  "to repair a damaged file? Note: changing only the sample "
85  "rate can cause \"mickey mouse\" effects."),
86  QString(),
87  i18n("&Convert"),
88  i18n("&Set Rate"));
89  if (res == KMessageBox::Yes) {
90  // Yes -> resample
91 
92  // take over all properties except the new sample rate, this will
93  // be detected and changed in the sample rate plugin
94  new_info.setRate(old_info.rate());
95  if (new_info != old_info) {
96  signalManager().setFileInfo(new_info, true);
97  } // else: nothing except sample rate changed
98 
99  // NOTE: this command could be executed asynchronously, thus
100  // we cannot change the sample rate afterwards
101  emitCommand(_("plugin:execute(samplerate,%1,all)").arg(new_rate));
102  return;
103  } else if (res == KMessageBox::No) {
104  // No -> only change the rate in the file info
105  new_info.setRate(new_rate);
106  } else {
107  // canceled -> use old sample rate
108  new_info.setRate(old_info.rate());
109  }
110  }
111 
112  // just copy all other properties
113  if (new_info != old_info) {
114  signalManager().setFileInfo(new_info, true);
115  }
116 }
117 
118 //***************************************************************************
119 #include "FileInfoPlugin.moc"
120 //***************************************************************************
121 //***************************************************************************
void emitCommand(const QString &command)
Definition: Plugin.cpp:510
static int questionYesNoCancel(QWidget *widget, QString message, QString caption=QString(), const QString buttonYes=QString(), const QString buttonNo=QString(), const QString &dontAskAgainName=QString())
Definition: MessageBox.cpp:74
Definition: App.h:33
double rate() const
Definition: FileInfo.cpp:415
QWidget * parentWidget() const
Definition: Plugin.cpp:450
Kwave::SignalManager & signalManager()
Definition: Plugin.cpp:444
void apply(Kwave::FileInfo &new_info)
void setRate(double rate)
Definition: FileInfo.cpp:424
void setFileInfo(const Kwave::FileInfo &new_info, bool with_undo)
Kwave::FileInfo & info()
virtual ~FileInfoPlugin() Q_DECL_OVERRIDE
#define KWAVE_PLUGIN(name, class)
Definition: Plugin.h:54
#define _(m)
Definition: memcpy.c:66
virtual QStringList * setup(QStringList &) Q_DECL_OVERRIDE