kwave  18.07.70
FileContext.h
Go to the documentation of this file.
1 /***************************************************************************
2  kwave/FileContext.h - Context of a Loaded File
3  -------------------
4  begin : 2009-12-31
5  copyright : (C) 2009 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 #ifndef KWAVE_FILE_CONTEXT_H
19 #define KWAVE_FILE_CONTEXT_H
20 
21 #include "config.h"
22 
23 #include <QtGlobal>
24 #include <QAtomicInt>
25 #include <QElapsedTimer>
26 #include <QList>
27 #include <QObject>
28 #include <QPointer>
29 #include <QString>
30 #include <QTimer>
31 #include <QUrl>
32 
33 #include "libkwave/MetaDataList.h"
34 #include "libkwave/Sample.h"
35 
36 class QApplication;
37 class QMdiSubWindow;
38 class QSize;
39 class QTextStream;
40 class QWidget;
41 
42 class QUrl;
43 
44 namespace Kwave
45 {
46 
47  class App;
48  class MainWidget;
49  class Parser;
50  class PluginManager;
51  class SignalManager;
52  class TopWidget;
53  class Zoomable;
54 
55  class Q_DECL_EXPORT FileContext: public QObject
56  {
57  Q_OBJECT
58  public:
64  explicit FileContext(Kwave::App &app);
65 
69  virtual ~FileContext();
70 
76  bool init(Kwave::TopWidget *top_widget);
77 
84  bool createMainWidget(const QSize &preferred_size);
85 
90  void setParent(Kwave::TopWidget *top_widget);
91 
93  Kwave::App &app() const { return m_application; }
94 
98  QWidget *mainWidget() const;
99 
101  Kwave::SignalManager *signalManager() const;
102 
104  Kwave::PluginManager *pluginManager() const;
105 
110  Kwave::Zoomable *zoomable() const;
111 
117  inline bool isEmpty() const { return m_main_widget.isNull(); }
118 
124  inline bool isActive() const { return m_active; }
125 
130  bool isInUse() const;
131 
133  QString signalName() const;
134 
136  inline int instanceNr() const { return m_instance_nr; }
137 
142  QString windowCaption(bool with_modified) const;
143 
149  int loadBatch(const QUrl &url);
150 
155  int saveFile();
156 
165  int saveFileAs(const QString &filename, bool selection = false);
166 
174  bool closeFile();
175 
176  protected:
177  friend class App;
178  friend class TopWidget;
179  friend class UsageGuard;
180 
185  void use();
186 
191  void release();
192 
193  signals:
194 
200  void sigStatusBarMessage(const QString &message, unsigned int ms);
201 
208  void sigZoomChanged(Kwave::FileContext *context, double zoom);
209 
214  void sigMetaDataChanged(Kwave::MetaDataList meta_data);
215 
221  void sigSelectionChanged(sample_index_t offset, sample_index_t length);
222 
227  void sigUndoRedoInfo(const QString &undo, const QString &redo);
228 
230  void sigVisibleRangeChanged(sample_index_t offset,
231  sample_index_t visible,
232  sample_index_t total);
233 
238  void sigModified();
239 
244  void destroyed(Kwave::FileContext *context);
245 
246  public slots:
247 
253  int executeCommand(const QString &command);
254 
255  private slots:
256 
261  void contextSwitched(Kwave::FileContext *context);
262 
267  void forwardZoomChanged(double zoom);
268 
273  void updatePlaybackPos(sample_index_t offset);
274 
279  void metaDataChanged(Kwave::MetaDataList meta_data);
280 
286  void selectionChanged(sample_index_t offset, sample_index_t length);
287 
293  void setUndoRedoInfo(const QString &undo, const QString &redo);
294 
301  void visibleRangeChanged(sample_index_t offset,
302  sample_index_t visible,
303  sample_index_t total);
304 
308  void modifiedChanged();
309 
311  void processDelayedCommand();
312 
313  private:
314 
316  {
317  public:
322  explicit UsageGuard(Kwave::FileContext *context)
323  :m_context(context)
324  {
325  if (m_context) m_context->use();
326  }
327 
329  virtual ~UsageGuard()
330  {
331  if (m_context) m_context->release();
332  m_context = Q_NULLPTR;
333  }
334 
335  private:
336  QPointer<Kwave::FileContext> m_context;
337  };
338 
339  private:
340 
345  void activated();
346 
352  void statusBarMessage(const QString &msg, unsigned int ms);
353 
360  int parseCommands(QTextStream &stream);
361 
367  void enqueueCommand(unsigned int delay, const QString &command);
368 
374  int revert();
375 
382  int delegateCommand(const char *plugin,
383  Kwave::Parser &parser,
384  unsigned int param_count);
385 
386  private:
387 
389  QAtomicInt m_use_count;
390 
393 
395  QPointer<Kwave::TopWidget> m_top_widget;
396 
398  QPointer<Kwave::MainWidget> m_main_widget;
399 
401  QPointer<Kwave::SignalManager> m_signal_manager;
402 
404  QPointer<Kwave::PluginManager> m_plugin_manager;
405 
407  bool m_active;
408 
410  double m_last_zoom;
411 
414 
417 
420 
423 
425  QString m_last_undo;
426 
428  QString m_last_redo;
429 
432 
435 
437  QList< QPair<unsigned int, QString> > m_delayed_command_queue;
438 
439  };
440 
441 }
442 
443 #endif /* KWAVE_FILE_CONTEXT_H */
444 
445 //***************************************************************************
446 //***************************************************************************
bool isActive() const
Definition: FileContext.h:124
QPointer< Kwave::MainWidget > m_main_widget
Definition: FileContext.h:398
QTimer m_delayed_command_timer
Definition: FileContext.h:434
Definition: App.h:33
QElapsedTimer m_last_status_message_timer
Definition: FileContext.h:419
QList< QPair< unsigned int, QString > > m_delayed_command_queue
Definition: FileContext.h:437
quint64 sample_index_t
Definition: Sample.h:28
int instanceNr() const
Definition: FileContext.h:136
UsageGuard(Kwave::FileContext *context)
Definition: FileContext.h:322
QAtomicInt m_use_count
Definition: FileContext.h:389
Definition: App.h:44
sample_index_t m_last_playback_pos
Definition: FileContext.h:413
QPointer< Kwave::PluginManager > m_plugin_manager
Definition: FileContext.h:404
QPointer< Kwave::SignalManager > m_signal_manager
Definition: FileContext.h:401
QString m_last_status_message_text
Definition: FileContext.h:416
QPointer< Kwave::FileContext > m_context
Definition: FileContext.h:336
bool isEmpty() const
Definition: FileContext.h:117
unsigned int m_last_status_message_ms
Definition: FileContext.h:422
QPointer< Kwave::TopWidget > m_top_widget
Definition: FileContext.h:395
Kwave::App & m_application
Definition: FileContext.h:392
Kwave::App & app() const
Definition: FileContext.h:93