00001
00002
00003 #include <mythtv/mythcontext.h>
00004 #include <mythtv/mythdbcon.h>
00005
00006
00007 #include "editmetadata.h"
00008
00009 EditMetadataDialog::EditMetadataDialog(ArchiveItem *source_metadata,
00010 MythMainWindow *parent,
00011 QString window_name,
00012 QString theme_filename,
00013 const char* name)
00014 :MythThemedDialog(parent, window_name, theme_filename, name)
00015 {
00016
00017 workMetadata = *source_metadata;
00018 sourceMetadata = source_metadata;
00019 wireUpTheme();
00020 fillWidgets();
00021 assignFirstFocus();
00022 }
00023
00024 void EditMetadataDialog::fillWidgets()
00025 {
00026 if (title_edit)
00027 {
00028 title_edit->setText(workMetadata.title);
00029 }
00030
00031 if (subtitle_edit)
00032 {
00033 subtitle_edit->setText(workMetadata.subtitle);
00034 }
00035
00036 if (description_edit)
00037 {
00038 description_edit->setText(workMetadata.description);
00039 }
00040
00041 if (startdate_edit)
00042 {
00043 startdate_edit->setText(workMetadata.startDate);
00044 }
00045
00046 if (starttime_edit)
00047 {
00048 starttime_edit->setText(workMetadata.startTime);
00049 }
00050 }
00051
00052 void EditMetadataDialog::keyPressEvent(QKeyEvent *e)
00053 {
00054 bool handled = false;
00055
00056 QStringList actions;
00057 gContext->GetMainWindow()->TranslateKeyPress("Global", e, actions);
00058
00059 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00060 {
00061 QString action = actions[i];
00062 handled = true;
00063
00064 if (action == "UP")
00065 nextPrevWidgetFocus(false);
00066 else if (action == "DOWN")
00067 nextPrevWidgetFocus(true);
00068 else if (action == "LEFT")
00069 {
00070
00071 }
00072 else if (action == "RIGHT")
00073 {
00074
00075 }
00076 else if (action == "SELECT")
00077 {
00078 activateCurrent();
00079 }
00080 else if (action == "0")
00081 {
00082 if (ok_button)
00083 ok_button->push();
00084 }
00085 else if (action == "1")
00086 {
00087 if (cancel_button)
00088 cancel_button->push();
00089 }
00090 else
00091 handled = false;
00092 }
00093
00094 if (!handled)
00095 MythThemedDialog::keyPressEvent(e);
00096 }
00097
00098 void EditMetadataDialog::wireUpTheme()
00099 {
00100 title_edit = getUIRemoteEditType("title_edit");
00101 if (title_edit)
00102 {
00103 title_edit->createEdit(this);
00104 connect(title_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
00105 }
00106
00107 subtitle_edit = getUIRemoteEditType("subtitle_edit");
00108 if (subtitle_edit)
00109 {
00110 subtitle_edit->createEdit(this);
00111 connect(subtitle_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
00112 }
00113
00114 description_edit = getUIRemoteEditType("description_edit");
00115 if (description_edit)
00116 {
00117 description_edit->createEdit(this);
00118 MythRemoteLineEdit *edit = (MythRemoteLineEdit *) description_edit->getEdit();
00119 if (edit)
00120 edit->setWordWrap(QTextEdit::WidgetWidth);
00121 connect(description_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
00122 }
00123
00124 startdate_edit = getUIRemoteEditType("startdate_edit");
00125 if (startdate_edit)
00126 {
00127 startdate_edit->createEdit(this);
00128 connect(startdate_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
00129 }
00130
00131 starttime_edit = getUIRemoteEditType("starttime_edit");
00132 if (starttime_edit)
00133 {
00134 starttime_edit->createEdit(this);
00135 connect(starttime_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
00136 }
00137
00138 ok_button = getUITextButtonType("ok_button");
00139 if (ok_button)
00140 {
00141 ok_button->setText(tr("Save"));
00142 connect(ok_button, SIGNAL(pushed()), this, SLOT(savePressed()));
00143 }
00144
00145 cancel_button = getUITextButtonType("cancel_button");
00146 if (cancel_button)
00147 {
00148 cancel_button->setText(tr("Cancel"));
00149 connect(cancel_button, SIGNAL(pushed()), this, SLOT(reject()));
00150 }
00151
00152 buildFocusList();
00153 }
00154
00155 void EditMetadataDialog::editLostFocus()
00156 {
00157 UIRemoteEditType *whichEditor = (UIRemoteEditType *) getCurrentFocusWidget();
00158
00159 if (whichEditor == title_edit)
00160 {
00161 workMetadata.title = title_edit->getText();
00162 }
00163 else if (whichEditor == subtitle_edit)
00164 {
00165 workMetadata.subtitle = subtitle_edit->getText();
00166 }
00167 else if (whichEditor == startdate_edit)
00168 {
00169 workMetadata.startDate = startdate_edit->getText();
00170 }
00171 else if (whichEditor == starttime_edit)
00172 {
00173 workMetadata.startTime = starttime_edit->getText();
00174 }
00175 else if (whichEditor == description_edit)
00176 {
00177 workMetadata.description = description_edit->getText();
00178 }
00179 }
00180
00181 void EditMetadataDialog::savePressed()
00182 {
00183 *sourceMetadata = workMetadata;
00184 sourceMetadata->editedDetails = true;
00185 done(kDialogCodeAccepted);
00186 }
00187
00188 EditMetadataDialog::~EditMetadataDialog()
00189 {
00190 }