00001 #ifndef LCDDEVICE_H_
00002 #define LCDDEVICE_H_
00003
00004 #include <iostream>
00005 using namespace std;
00006
00007 #include <qobject.h>
00008 #include <qstringlist.h>
00009 #include <qvaluevector.h>
00010 #include <qsocket.h>
00011 #include <qtimer.h>
00012 #include <qdatetime.h>
00013 #include <qmutex.h>
00014
00015 #include "mythsocket.h"
00016 #include "mythexp.h"
00017
00018 enum CHECKED_STATE {CHECKED = 0, UNCHECKED, NOTCHECKABLE };
00019
00020 class MPUBLIC LCDMenuItem
00021 {
00022 public:
00023 LCDMenuItem() {}
00024 LCDMenuItem(bool item_selected, CHECKED_STATE item_checked,
00025 QString item_name, unsigned int item_indent = 0)
00026 {
00027 selected = item_selected;
00028 checked = item_checked;
00029 name = item_name;
00030 indent = item_indent;
00031 scrollPosition = indent;
00032 }
00033
00034 ~LCDMenuItem() {}
00035
00036 CHECKED_STATE isChecked() { return checked; }
00037 bool isSelected() { return selected; }
00038 QString ItemName() { return name; }
00039 bool Scroll() { return scroll; }
00040 unsigned int getIndent() { return indent; }
00041 unsigned int getScrollPos() { return scrollPosition; }
00042
00043 void setChecked(CHECKED_STATE value) { checked = value; }
00044 void setSelected(bool value) { selected = value; }
00045 void setItemName(QString value) { name = value; }
00046 void setScroll(bool value) { scroll = value; }
00047 void setIndent(unsigned int value) { indent = value; }
00048 void setScrollPos(unsigned int value) { scrollPosition = value; }
00049 void incrementScrollPos() { ++scrollPosition; }
00050
00051 private:
00052 bool selected;
00053 CHECKED_STATE checked;
00054 QString name;
00055 bool scroll;
00056 unsigned int indent;
00057 unsigned int scrollPosition;
00058 };
00059
00060 enum TEXT_ALIGNMENT {ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTERED };
00061
00062 class MPUBLIC LCDTextItem
00063 {
00064 public:
00065 LCDTextItem() {}
00066 LCDTextItem(unsigned int row, TEXT_ALIGNMENT align, QString text,
00067 QString screen = "Generic", bool scroll = false,
00068 QString widget = "textWidget")
00069 {
00070 itemRow = row;
00071 itemAlignment = align;
00072 itemText = text;
00073 itemScreen = screen;
00074 itemWidget = widget;
00075 itemScrollable = scroll;
00076 }
00077
00078 ~LCDTextItem(){};
00079
00080 unsigned int getRow() { return itemRow; }
00081 TEXT_ALIGNMENT getAlignment() { return itemAlignment; }
00082 QString getText() { return itemText; }
00083 QString getScreen() { return itemScreen; }
00084 QString getWidget() { return itemWidget; }
00085 int getScroll() { return itemScrollable; }
00086
00087 void setRow(unsigned int value) { itemRow = value; }
00088 void setAlignment(TEXT_ALIGNMENT value) { itemAlignment = value; }
00089 void setText(QString value) { itemText = value; }
00090 void setScreen(QString value) { itemScreen = value; }
00091 void setWidget(QString value) { itemWidget = value; }
00092 void setScrollable(bool value) { itemScrollable = value; }
00093
00094 private:
00095 unsigned int itemRow;
00096 TEXT_ALIGNMENT itemAlignment;
00097 QString itemText;
00098 QString itemScreen;
00099 QString itemWidget;
00100 bool itemScrollable;
00101 };
00102
00103 class MPUBLIC LCD : public QObject, public MythSocketCBs
00104 {
00105 Q_OBJECT
00106
00107 protected:
00108 LCD();
00109
00110 static bool m_server_unavailable;
00111 static class LCD * m_lcd;
00112 static bool m_enabled;
00113
00114 public:
00115 ~LCD();
00116
00117 enum {
00118 MUSIC_REPEAT_NONE = 0,
00119 MUSIC_REPEAT_TRACK = 1,
00120 MUSIC_REPEAT_ALL = 2,
00121 };
00122
00123 enum {
00124 MUSIC_SHUFFLE_NONE = 0,
00125 MUSIC_SHUFFLE_RAND = 1,
00126 MUSIC_SHUFFLE_SMART = 2,
00127 MUSIC_SHUFFLE_ALBUM = 3,
00128 MUSIC_SHUFFLE_ARTIST = 4
00129 };
00130
00131 static class LCD * Get(void);
00132 static void SetupLCD (void);
00133
00134
00135 bool connectToHost(const QString &hostname, unsigned int port);
00136
00137
00138 void switchToTime();
00139
00140
00141
00142
00143
00144
00145 void switchToMusic(const QString &artist, const QString &album, const QString &track);
00146
00147
00148 void setLevels(int numbLevels, float *values);
00149
00150
00151
00152
00153
00154
00155 void switchToChannel(QString channum = "", QString title = "",
00156 QString subtitle = "");
00157
00158
00159
00160
00161 void setChannelProgress(float percentViewed);
00162
00163
00164
00165
00166 void switchToMenu(QPtrList<LCDMenuItem> *menuItems, QString app_name = "",
00167 bool popMenu = true);
00168
00169
00170
00171
00172 void switchToGeneric(QPtrList<LCDTextItem> *textItems);
00173
00177 void setGenericProgress(float generic_progress);
00178
00183 void setGenericBusy();
00184
00185
00186 void setMusicProgress(QString time, float generic_progress);
00187
00191 void setMusicRepeat(int repeat);
00192
00196 void setMusicShuffle(int shuffle);
00197
00198
00199 void switchToVolume(QString app_name);
00200
00201
00202 void setVolumeLevel(float volume_level);
00203
00204
00205
00206
00207 void switchToNothing();
00208
00209
00210
00211 void shutdown();
00212
00213 void setupLEDs(int(*LedMaskFunc)(void));
00214
00215 void stopAll(void);
00216
00217 uint getLCDHeight(void) { return lcd_height; }
00218 uint getLCDWidth(void) { return lcd_width; }
00219
00220 void resetServer(void);
00221
00222 private slots:
00223 void restartConnection();
00224
00225 void outputLEDs();
00226
00227 private:
00228 void sendToServer(const QString &someText);
00229 void init();
00230 void handleKeyPress(QString key);
00231 QString quotedString(const QString &s);
00232 void describeServer();
00233
00234
00235 void connected(MythSocket *sock) { (void)sock; }
00236 void connectionClosed(MythSocket *sock);
00237 void readyRead(MythSocket *sock);
00238 void connectionFailed(MythSocket *sock);
00239
00240 MythSocket *socket;
00241 QMutex socketLock;
00242 QString hostname;
00243 uint port;
00244 bool bConnected;
00245
00246 QTimer *retryTimer;
00247 QTimer *LEDTimer;
00248
00249 QString send_buffer;
00250 QString last_command;
00251
00252 int lcd_width;
00253 int lcd_height;
00254
00255 bool lcd_ready;
00256
00257 bool lcd_showtime;
00258 bool lcd_showmenu;
00259 bool lcd_showgeneric;
00260 bool lcd_showmusic;
00261 bool lcd_showchannel;
00262 bool lcd_showvolume;
00263 bool lcd_showrecstatus;
00264 bool lcd_backlighton;
00265 bool lcd_heartbeaton;
00266 int lcd_popuptime;
00267 QString lcd_showmusic_items;
00268 QString lcd_keystring;
00269
00270 int (*GetLEDMask)(void);
00271 };
00272
00273 #endif