1 /*
2 *  qm_libraryview.h
3 *  QUIMUP library treeview
4 *  © 2008-2018 Johan Spee
5 *
6 *  This file is part of Quimup
7 *
8 *  QUIMUP is free software: you can redistribute it and/or modify
9 *  it under the terms of the GNU General Public License as published by
10 *  the Free Software Foundation, either version 3 of the License, or
11 *  (at your option) any later version.
12 *
13 *  QUIMUP is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 *  GNU General Public License for more details.
17 *
18 *  You should have received a copy of the GNU General Public License
19 *  along with this program. If not, see http://www.gnu.org/licenses/.
20 */
21 
22 #ifndef QM_LIBRARY_H
23 #define QM_LIBRARY_H
24 
25 #include <QtWidgets>
26 #include <QTreeWidget>
27 #include <QHeaderView>
28 #include <QTreeWidgetItem>
29 #include <QKeyEvent>
30 #include <QMenu>
31 #include <QFile>
32 #include <QMessageBox>
33 #include <QProcess>
34 #include "qm_songinfo.h"
35 #include "qm_mpdcom.h"
36 #include "qm_itemlist.h"
37 #include "qm_commandlist.h"
38 #include "qm_browser_ids.h"
39 #include "qm_config.h"
40 
41 #define setdummy(dm)  setData(0, Qt::UserRole +  1, dm)
42 #define settype(tp)  setData(0, Qt::UserRole +  2, tp)
43 #define settime(tm)  setData(0, Qt::UserRole +  3, tm)
44 #define setartist(at)  setData(0, Qt::UserRole +  4, at)
45 #define setalbum(ab) setData(0, Qt::UserRole +  5, ab)
46 #define settitle(tt) setData(0, Qt::UserRole +  6, tt)
47 #define setfile(fl)  setData(0, Qt::UserRole +  8, fl)
48 #define settrack(tr)  setData(0, Qt::UserRole +  9, tr)
49 #define setname(nm)  setData(0, Qt::UserRole + 10, nm)
50 #define setgenre(gr)  setData(0, Qt::UserRole + 12, gr)
51 
52 #define getdummy  data(0, Qt::UserRole +  1).toInt()
53 #define gettype   data(0, Qt::UserRole +  2).toInt()
54 #define gettime   data(0, Qt::UserRole +  3).toInt()
55 #define getartist   data(0, Qt::UserRole +  4).toString()
56 #define getalbum  data(0, Qt::UserRole +  5).toString()
57 #define gettitle  data(0, Qt::UserRole +  6).toString()
58 #define getfile   data(0, Qt::UserRole +  8).toString()
59 #define gettrack   data(0, Qt::UserRole +  9).toString()
60 #define getname   data(0, Qt::UserRole + 10).toString()
61 #define getgenre   data(0, Qt::UserRole + 12).toString()
62 
63 class qm_libview : public QTreeWidget
64 {
65 	Q_OBJECT
66 
67 public:
68     qm_libview(QWidget * parent = nullptr);
69 	virtual ~qm_libview();
70 
71 public slots:
72 	void set_connected(qm_mpdCom*, bool);
73 	void set_config(qm_config*);
74 	void reload_root();
75 	void on_plist_dropreceived(int);
76 	void set_panel_maxmode(bool);
77 	void set_auto_columns();
78 
79 protected slots:
80     void columnResized(int, int, int);
81 
82 private slots:
83 	void on_item_expanded(QTreeWidgetItem *);
84 	void on_selection_changed();
85 	void on_append();
86 	void on_createnew();
87 	void on_delete();
88 	void on_opendir();
89 	void on_tagedit();
90 	void on_update();
91 	void startDrag(Qt::DropActions);
92 	void on_mpd_plistsaved();
93 
94 private:
95     bool b_mpd_connected,
96         b_setup_done = false;
97 	int plist_droppos,
98 		searched_mode_used,
99 		b_panel_max,
100 		column_count;
101 	qm_mpdCom *mpdCom;
102 	qm_config *config;
103 	QMenu *context_menu;
104 	QAction *a_delete;
105 	QAction *a_opendir;
106 	QAction *a_update;
107 	QAction *a_tagedit;
108 	QHeaderView *libhview;
109 
110 	qm_commandList playlist_modification_list;
111 	void get_albums(QString searchfor = "*^*", bool sort_by_date = false);
112 	void get_artists(QString searchfor = "*^*");
113 	void get_genres(QString searchfor = "*^*");
114 	void get_songs(QString searchfor = "*^*");
115 	void get_playlists();
116 	void get_directories();
117 	void get_directories(QString); // search
118 	void get_albums_year();
119 	void expand_album(QTreeWidgetItem *);
120 	void expand_artist(QTreeWidgetItem *);
121 	void expand_playlist(QTreeWidgetItem *);
122 	void expand_directory(QTreeWidgetItem *);
123 	void expand_genre(QTreeWidgetItem *);
124 	void add_dummy_to(QTreeWidgetItem *);
125 	void take_dummy_from(QTreeWidgetItem *);
126 	void contextMenuEvent(QContextMenuEvent *);
127 	void add_songdata_toItem(QTreeWidgetItem *, qm_listitemInfo);
128 	void modify_playlist(bool, bool);
129 	void append_to_modlist(QString, QString, QString, bool);
130 	void append_to_modlist_dir(QString, bool);
131 	void append_to_modlist_plist(QString, bool);
132 	void set_column_count(int);
133 	void fix_header();
134 };
135 
136 #endif //  QM_LIBRARY_H
137