mainwindow.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QMainWindow>
  4. #include <QTimer>
  5. #include "sortdialog.h"
  6. namespace Ui {
  7. class MainWindow;
  8. }
  9. // libqtmultimediakit from Qt Mobility 1.1.3 or later
  10. #include <QMediaPlaylist>
  11. #include <QMediaPlayer>
  12. class QModelIndex;
  13. class PlayListListModel;
  14. class PlaylistModel;
  15. class QAbstractListModel;
  16. class QDeclarativeItem;
  17. class ItemsListModel;
  18. class SubscriptionListModel;
  19. /** A small-screen Playlist View Main Window.
  20. Originally based on qtmobility-1.1/demos/player.
  21. @author Alan Ezust
  22. */
  23. class MainWindow : public QMainWindow
  24. {
  25. Q_OBJECT
  26. // width and height of the QML view area.
  27. Q_PROPERTY(int qmlWidth READ qmlWidth NOTIFY qmlResized);
  28. Q_PROPERTY(int qmlHeight READ qmlHeight NOTIFY qmlResized);
  29. // index of playlist item chosen from QML listview
  30. Q_PROPERTY(int chosenFromQML READ chosenFromQML WRITE setChosenFromQML NOTIFY chosenFromQMLChanged);
  31. // What the user chose from the drop-down menu
  32. Q_PROPERTY(QString showOption READ showOption WRITE setShowOption NOTIFY showOptionChanged);
  33. // Current playlist playing.
  34. Q_PROPERTY(QString currentM3u READ currentM3u WRITE setCurrentM3u NOTIFY currentM3uChanged);
  35. // Title of current playlist
  36. Q_PROPERTY(QString m3uTitle READ m3uTitle WRITE setM3uTitle NOTIFY m3uTitleChanged);
  37. // True if the play queue is empty
  38. Q_PROPERTY(bool isQueueEmpty READ isQueueEmpty NOTIFY playListChanged);
  39. // true if the playlist is empty
  40. Q_PROPERTY(bool isPlayListEmpty READ isPlayListEmpty NOTIFY playListChanged);
  41. public:
  42. explicit MainWindow(QWidget *parent = 0);
  43. ~MainWindow();
  44. static MainWindow* instance();
  45. void resizeEvent(QResizeEvent * e);
  46. protected:
  47. // based on order added in designer
  48. enum {Subscriptions = 4, NowPlaying = 5};
  49. void saveSettings();
  50. void restoreSettings();
  51. void changeEvent(QEvent *e);
  52. void closeEvent(QCloseEvent *);
  53. signals:
  54. void changeVolume(int volume);
  55. void changeMuting(bool muting);
  56. void qmlResized();
  57. void playListChanged();
  58. void showOptionChanged();
  59. void chosenFromQMLChanged();
  60. void currentM3uChanged();
  61. void m3uTitleChanged();
  62. public slots:
  63. bool isQueueEmpty() const;
  64. bool isPlayListEmpty() const;
  65. void close();
  66. QString currentM3u() const;
  67. void setCurrentM3u(QString v) ;
  68. QString m3uTitle() const ;
  69. void setM3uTitle(QString t) ;
  70. /** called from MainMenu.qml - to decide what we are showing in the center listview */
  71. void setShowOption(QString option);
  72. QString showOption() const;
  73. void showPlayList();
  74. void on_actionSort_Playlist_triggered();
  75. void showSubscriptions();
  76. void hideSubscriptions();
  77. void showParentList();
  78. void on_actionAddFeed_triggered();
  79. void on_reloadButton_clicked();
  80. int chosenFromQML() const {return m_chosenFromQML;}
  81. void setChosenFromQML(int i);
  82. void clickEpisode(int i);
  83. void restoreSortedOrder();
  84. void sortByOption(SortDialog::Option o);
  85. void playQmlSelected();
  86. int qmlWidth() const;
  87. int qmlHeight() const;
  88. /** User selects an item in the parent list indicating we should load a playlist
  89. @param index in the m3uListModel */
  90. void openPlayListI(int index);
  91. /** Open a m3u file or a directory
  92. @param path if a folder, scans for all playable tracks in
  93. that directory and generates a playlist based on that
  94. */
  95. void openPlayList(QString path);
  96. void addToPlaylist(const QStringList& fileNames);
  97. /** called when user clicks on a row in the playlist */
  98. void jump(const QModelIndex &index);
  99. void seek(int seconds);
  100. /** Slot notified when the player changes what it is playing. */
  101. void updateNowPlaying(int rowIndex);
  102. void statusChanged(QMediaPlayer::MediaStatus status);
  103. void bufferingProgress(int progress);
  104. void displayErrorMessage();
  105. void on_playButton_clicked();
  106. void on_actionQuit_triggered();
  107. void on_actionOpen_triggered();
  108. void toggleQueue();
  109. void enqueue(QString urlString);
  110. int positionInQueue(QString urlString);
  111. void setTrackInfo(const QString &info);
  112. void setStatusInfo(const QString &info);
  113. void handleCursor(QMediaPlayer::MediaStatus status);
  114. void updateTrackInfo();
  115. void updateStatusInfo();
  116. void updateState(QMediaPlayer::State state);
  117. void updateDurationInfo(qint64 currentInfo);
  118. void updatePositionInfo(qint64 positionInfo);
  119. // Auto-generated slots connected to designer ui signals:
  120. private slots:
  121. void disableSeekUpdates();
  122. void enableSeekUpdates();
  123. void on_previousButton_clicked();
  124. void on_nextButton_clicked();
  125. void on_actionPlay_Pause_triggered();
  126. void on_actionAbout_triggered();
  127. void on_actionAboutQt_triggered();
  128. void on_actionVolumeToggle_toggled(bool );
  129. void on_actionVolumeUp_triggered();
  130. void on_actionVolumeDown_triggered();
  131. void on_actionNextTrack_triggered();
  132. void on_actionPreviousTrack_triggered();
  133. void on_actionAdd_Playlist_Dir_triggered();
  134. void on_actionClear_Settings_triggered();
  135. void on_actionAdd_Song_Dir_triggered();
  136. void on_actionShuffle_triggered();
  137. void showVolumeSliderBriefly();
  138. void on_actionSet_Podcast_Dir_triggered();
  139. // called between tracks from the regular playlists - check
  140. // if something is queued.
  141. void checkQueue();
  142. // called between tracks when the queue is playing
  143. void updateQueue(int i);
  144. /** @return a QDeclarativeItem loaded from a .qml file,
  145. that we can add to a graphicsscene ourselves */
  146. QDeclarativeItem* createFromResource(QString url);
  147. void on_nextButton_pressed();
  148. void on_nextButton_released();
  149. void jumpAhead();
  150. void jumpBackward();
  151. void on_previousButton_pressed();
  152. void on_previousButton_released();
  153. void on_durationButton_clicked(bool checked);
  154. void on_actionHelp_triggered();
  155. private:
  156. QMediaPlayer* newPlayer();
  157. Ui::MainWindow *ui;
  158. qint64 m_position; // in seconds
  159. qint64 m_duration; // in seconds
  160. bool m_showElapsed;
  161. QMediaPlayer::State m_state;
  162. QString m_statusInfo;
  163. QString m_trackInfo;
  164. // What is selected from the MainMenu:
  165. QString m_showOption;
  166. bool m_seekUpdates;
  167. QMediaPlayer *m_player;
  168. QString m_currentPlaylist;
  169. QMediaPlaylist *m_playList;
  170. QMediaPlaylist *m_queue;
  171. PlayListListModel *m_m3uListModel;
  172. SubscriptionListModel *m_subscriptionListModel;
  173. QAbstractListModel *m_currentParentModel;
  174. PlaylistModel *m_playListModel;
  175. ItemsListModel* m_itemsListModel;
  176. QDeclarativeItem *m_flickableView;
  177. QDeclarativeItem *m_parentListView;
  178. QDeclarativeItem *m_playListView;
  179. QDeclarativeItem *m_podcastView;
  180. QDeclarativeItem *m_mainMenu;
  181. QDeclarativeItem *m_subscriptionView;
  182. QDeclarativeItem *m_helpDialog;
  183. QString m_m3utitle;
  184. int m_chosenFromQML;
  185. QTimer m_fastForwardTimer;
  186. QTimer m_rewindTimer;
  187. bool m_fastForward, m_rewind;
  188. static MainWindow* sm_instance;
  189. };
  190. #endif // MAINWINDOW_H