Sayonara Player
PlaylistMode.h
1 /* PlaylistMode.h */
2 
3 /* Copyright (C) 2011 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef PLAYLISTMODE_H_
23 #define PLAYLISTMODE_H_
24 
25 
26 #include <iostream>
27 #include <QList>
28 #include <QVariant>
29 #include <QStringList>
30 #include <QDebug>
31 
32 using namespace std;
33 
34 struct PlaylistMode {
35 
36  bool rep1;
37  bool repAll;
38  bool repNone;
39  bool append;
40  bool shuffle;
41  bool dynamic;
42  bool gapless;
43 
44  bool ui_rep1;
45  bool ui_repAll;
46  bool ui_append;
47  bool ui_shuffle;
48  bool ui_dynamic;
49  bool ui_gapless;
50 
51  PlaylistMode(){
52  rep1 = false;
53  repAll = false;
54  repNone = true;
55  append = false;
56  shuffle = false;
57  gapless = false;
58  dynamic = false;
59 
60  ui_rep1 = true;
61  ui_repAll = true;
62  ui_append = true;
63  ui_shuffle = true;
64  ui_dynamic = true;
65  ui_gapless = true;
66  }
67 
68 
69  void print(){
70  cout << "rep1 = " << rep1 << ", "
71  << "repAll = " << repAll << ", "
72  << "repNone = " << repNone << ", "
73  << "append = " << append <<", "
74  << "dynamic = " << dynamic << ","
75  << "gapless = " << gapless << endl;
76 
77  }
78 
79  QString toString() const {
80  QString str;
81  str += (append ? "1" : "0") + QString(",");
82  str += (repAll ? "1" : "0") + QString(",");
83  str += (rep1 ? "1" : "0") + QString(",");
84  str += (repNone ? "1" : "0") + QString(",");
85  str += (shuffle ? "1" : "0") + QString(",");
86  str += (dynamic ? "1" : "0") + QString(",");
87  str += (gapless ? "1" : "0");
88 
89  return str;
90  }
91 
92  static PlaylistMode fromString(QString str){
93 
94  PlaylistMode plm;
95  QStringList list = str.split(',');
96 
97  if(list.size() < 6) return plm;
98 
99  plm.append = list[0].toInt() == 1;
100  plm.repAll = list[1].toInt() == 1;
101  plm.rep1 = list[2].toInt() == 1;
102  plm.repNone = list[3].toInt() == 1;
103  plm.shuffle = list[4].toInt() == 1;
104  plm.dynamic = list[5].toInt() == 1;
105 
106  if(list.size() > 6){
107  plm.gapless = list[6].toInt() == 1;
108  }
109 
110  return plm;
111  }
112 
113  bool operator==(const PlaylistMode& pm) const {
114 
115  if(pm.append != append) return false;
116  if(pm.repAll != repAll) return false;
117  if(pm.rep1 != rep1) return false;
118  if(pm.shuffle != shuffle) return false;
119  if(pm.dynamic != dynamic) return false;
120  if(pm.gapless != gapless) return false;
121 
122  return true;
123  }
124 };
125 
126 #endif
Definition: PlaylistMode.h:34