00001 #include <qlayout.h>
00002 #include <qpushbutton.h>
00003 #include <qlabel.h>
00004 #include <qdatetime.h>
00005 #include <qcursor.h>
00006 #include <qcheckbox.h>
00007 #include <qvgroupbox.h>
00008 #include <qapplication.h>
00009 #include <qlistview.h>
00010 #include <qheader.h>
00011
00012 #include <iostream>
00013 using namespace std;
00014
00015 #include "infodialog.h"
00016 #include "infostructs.h"
00017 #include "programinfo.h"
00018 #include "oldsettings.h"
00019 #include "mythcontext.h"
00020 #include "proglist.h"
00021
00022 class RecListItem : public QListViewItem
00023 {
00024 public:
00025 RecListItem(QListView *parent, QString text, RecordingType type)
00026 : QListViewItem(parent, text)
00027 { m_type = type; }
00028
00029 ~RecListItem() { }
00030
00031 RecordingType GetType(void) { return m_type; }
00032
00033 private:
00034 RecordingType m_type;
00035 };
00036
00037 InfoDialog::InfoDialog(ProgramInfo *pginfo, MythMainWindow *parent,
00038 const char *name)
00039 : MythDialog(parent, name)
00040 {
00041 myinfo = new ProgramInfo(*pginfo);
00042
00043 QFont mediumfont = gContext->GetMediumFont();
00044
00045 QVBoxLayout *vbox = new QVBoxLayout(this, (int)(20 * wmult));
00046
00047 if (myinfo)
00048 {
00049 QGridLayout *grid = myinfo->DisplayWidget(this, "");
00050 vbox->addLayout(grid);
00051 }
00052
00053 QFrame *f = new QFrame(this);
00054 f->setFrameStyle(QFrame::HLine | QFrame::Plain);
00055 f->setLineWidth((int)(4 * hmult));
00056 vbox->addWidget(f);
00057
00058 programtype = myinfo->IsProgramRecurring();
00059 recordstatus = myinfo->GetProgramRecordingStatus();
00060
00061 if (recordstatus == kTimeslotRecord && programtype == 0)
00062 {
00063 cerr << "error, somehow set to record timeslot and it doesn't seem to "
00064 "have one\n";
00065 recordstatus = kSingleRecord;
00066 }
00067
00068 RecListItem *selectItem = NULL;
00069
00070 lview = new MythListView(this);
00071 lview->addColumn("Selections");
00072 lview->setColumnWidth(0, (int)(750 * wmult));
00073 lview->setSorting(-1, false);
00074 lview->setAllColumnsShowFocus(true);
00075 lview->setItemMargin((int)(hmult * mediumfont.pointSize() / 2));
00076 lview->setFixedHeight((int)(225 * hmult));
00077 lview->header()->hide();
00078
00079 lview->installEventFilter(this);
00080
00081 RecListItem *item;
00082
00083 if (recordstatus != kOverrideRecord && recordstatus != kDontRecord)
00084 {
00085
00086 item = new RecListItem(lview, tr("Record this program whenever "
00087 "it's shown anywhere"), kAllRecord);
00088 if (recordstatus == kAllRecord)
00089 selectItem = item;
00090
00091 item = new RecListItem(lview, tr("Record this program whenever it's "
00092 "shown on this channel"),
00093 kChannelRecord);
00094 if (recordstatus == kChannelRecord)
00095 selectItem = item;
00096
00097 QString msg = "Shouldn't show up.";
00098 RecordingType rt = kNotRecording;
00099 if (programtype == 2 ||
00100 programtype == -1 ||
00101 recordstatus == kWeekslotRecord)
00102 {
00103 msg = tr("Record this program in this timeslot every week");
00104 rt = kTimeslotRecord;
00105 }
00106 else if (programtype == 1)
00107 {
00108 msg = tr("Record this program in this timeslot every day");
00109 rt = kTimeslotRecord;
00110 }
00111
00112 if (programtype != 0)
00113 {
00114 item = new RecListItem(lview, msg, rt);
00115 if ((recordstatus == kTimeslotRecord) ||
00116 (recordstatus == kWeekslotRecord))
00117 selectItem = item;
00118 }
00119
00120 if (recordstatus == kFindOneRecord)
00121 {
00122 msg = tr("Record one showing of this title");
00123 rt = kFindOneRecord;
00124 item = new RecListItem(lview, msg, kFindOneRecord);
00125 selectItem = item;
00126 }
00127
00128 item = new RecListItem(lview, tr("Record only this showing of the "
00129 "program"), kSingleRecord);
00130 if (recordstatus == kSingleRecord)
00131 selectItem = item;
00132
00133 item = new RecListItem(lview, tr("Don't record this program"),
00134 kNotRecording);
00135 if (selectItem == NULL)
00136 selectItem = item;
00137 }
00138 else
00139 {
00140 item = new RecListItem(lview, tr("Don't record this showing"),
00141 kDontRecord);
00142 if (recordstatus == kDontRecord)
00143 selectItem = item;
00144
00145 item = new RecListItem(lview, tr("Record this showing with override "
00146 "options"), kOverrideRecord);
00147 if (recordstatus == kOverrideRecord)
00148 selectItem = item;
00149
00150 item = new RecListItem(lview, tr("Record this showing with normal "
00151 "options"), kNotRecording);
00152 if (selectItem == NULL)
00153 selectItem = item;
00154 }
00155
00156 vbox->addWidget(lview, 0);
00157
00158 f = new QFrame(this);
00159 f->setFrameStyle(QFrame::HLine | QFrame::Plain);
00160 f->setLineWidth((int)(4 * hmult));
00161 vbox->addWidget(f);
00162
00163 QLabel *legend1 = new QLabel(tr("To go to the advanced recordings screen, "
00164 "press 'i'"), this);
00165 legend1->setBackgroundOrigin(WindowOrigin);
00166 vbox->addWidget(legend1, 0);
00167
00168 QLabel *legend2 = new QLabel(tr("To see a list of all up-coming showings "
00169 "of this program, press '5'"), this);
00170 legend2->setBackgroundOrigin(WindowOrigin);
00171 vbox->addWidget(legend2, 0);
00172
00173 lview->setCurrentItem(selectItem);
00174 lview->setSelected(selectItem, true);
00175
00176 lview->setFocus();
00177
00178 }
00179
00180 InfoDialog::~InfoDialog()
00181 {
00182 delete myinfo;
00183 }
00184
00185 QLabel *InfoDialog::getDateLabel(ProgramInfo *pginfo)
00186 {
00187 QDateTime startts = pginfo->startts;
00188 QDateTime endts = pginfo->endts;
00189
00190 QString dateformat = gContext->GetSetting("DateFormat", "ddd MMMM d");
00191 QString timeformat = gContext->GetSetting("TimeFormat", "h:mm AP");
00192
00193 QString timedate = startts.date().toString(dateformat) + QString(", ") +
00194 startts.time().toString(timeformat) + QString(" - ") +
00195 endts.time().toString(timeformat);
00196
00197 QLabel *date = new QLabel(timedate, this);
00198
00199 return date;
00200 }
00201
00202 bool InfoDialog::eventFilter(QObject *o, QEvent *e)
00203 {
00204 (void)o;
00205
00206 if (e->type() != QEvent::KeyPress)
00207 return false;
00208
00209 QKeyEvent *ke = (QKeyEvent *)e;
00210
00211 bool handled = false;
00212 QStringList actions;
00213 gContext->GetMainWindow()->TranslateKeyPress("qt", ke, actions);
00214
00215 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00216 {
00217 QString action = actions[i];
00218 handled = true;
00219
00220 if (action == "MENU" || action == "INFO")
00221 advancedEdit(lview->currentItem());
00222 else if (action == "SELECT")
00223 selected(lview->currentItem());
00224 else if (action == "0" || action == "1" || action == "2" ||
00225 action == "3" || action == "4" || action == "5" ||
00226 action == "6" || action == "7" || action == "8" ||
00227 action == "9")
00228 {
00229 numberPress(lview->currentItem(), action.toInt());
00230 }
00231 else
00232 handled = false;
00233 }
00234
00235 return handled;
00236 }
00237
00238 void InfoDialog::selected(QListViewItem *selitem)
00239 {
00240 RecordingType currentSelected = kNotRecording;
00241
00242 QListViewItem *item = lview->firstChild();
00243
00244 while (item && item != lview->currentItem())
00245 item = item->nextSibling();
00246
00247 if (!item)
00248 item = lview->firstChild();
00249
00250 RecListItem *realitem = (RecListItem *)item;
00251
00252 currentSelected = realitem->GetType();
00253
00254 if (currentSelected != recordstatus)
00255 myinfo->ApplyRecordStateChange(currentSelected);
00256
00257 if (selitem)
00258 accept();
00259 }
00260
00261 void InfoDialog::advancedEdit(QListViewItem *)
00262 {
00263 ScheduledRecording record;
00264 record.loadByProgram(myinfo);
00265
00266 setFocusPolicy(QWidget::NoFocus);
00267 lview->setFocusPolicy(QWidget::NoFocus);
00268 record.exec();
00269
00270 reject();
00271 }
00272
00273 void InfoDialog::numberPress(QListViewItem *, int num)
00274 {
00275 if (num == 5)
00276 {
00277 ProgLister *pl = new ProgLister(plTitle, myinfo->title,
00278 gContext->GetMainWindow(), "proglist");
00279 pl->exec();
00280 delete pl;
00281
00282 lview->setFocus();
00283 }
00284 }