MythTV  0.26-pre
editvideometadata.cpp
Go to the documentation of this file.
00001 #include <algorithm>
00002 
00003 #include <QImageReader>
00004 #include <QUrl>
00005 
00006 #include <mythcontext.h>
00007 #include <mythdirs.h>
00008 
00009 #include "mythmainwindow.h"
00010 #include "mythdialogbox.h"
00011 #include "mythuibuttonlist.h"
00012 #include "mythuitext.h"
00013 #include "mythuitextedit.h"
00014 #include "mythuibutton.h"
00015 #include "mythuicheckbox.h"
00016 #include "mythuispinbox.h"
00017 #include "mythuifilebrowser.h"
00018 #include "mythuiimageresults.h"
00019 #include "mythuihelper.h"
00020 #include "mythprogressdialog.h"
00021 #include "remoteutil.h"
00022 #include "globals.h"
00023 #include "dbaccess.h"
00024 #include "videometadatalistmanager.h"
00025 #include "videoutils.h"
00026 
00027 #include "editvideometadata.h"
00028 
00029 EditMetadataDialog::EditMetadataDialog(MythScreenStack *lparent,
00030         QString lname, VideoMetadata *source_metadata,
00031         const VideoMetadataListManager &cache) : MythScreenType(lparent, lname),
00032     m_origMetadata(source_metadata), m_titleEdit(0), m_subtitleEdit(0),
00033     m_taglineEdit(0), m_playerEdit(0), m_ratingEdit(0), m_directorEdit(0),
00034     m_inetrefEdit(0), m_homepageEdit(0), m_plotEdit(0), m_seasonSpin(0),
00035     m_episodeSpin(0), m_yearSpin(0), m_userRatingSpin(0), m_lengthSpin(0),
00036     m_categoryList(0), m_levelList(0), m_childList(0), m_browseCheck(0),
00037     m_watchedCheck(0), m_coverartButton(0), m_coverartText(0),
00038     m_screenshotButton(0), m_screenshotText(0), m_bannerButton(0),
00039     m_bannerText(0), m_fanartButton(0), m_fanartText(0),
00040     m_trailerButton(0), m_trailerText(0),
00041     m_netCoverartButton(0), m_netFanartButton(0), m_netBannerButton(0),
00042     m_netScreenshotButton(0), m_coverart(0), m_screenshot(0),
00043     m_banner(0), m_fanart(0),
00044     m_doneButton(0),
00045     cachedChildSelection(0),
00046     m_metaCache(cache), m_busyPopup(0)
00047 {
00048     m_query = new MetadataDownload(this);
00049     m_imageDownload = new MetadataImageDownload(this);
00050     m_workingMetadata = new VideoMetadata(*m_origMetadata);
00051 
00052     m_popupStack = GetMythMainWindow()->GetStack("popup stack");
00053 }
00054 
00055 EditMetadataDialog::~EditMetadataDialog()
00056 {
00057     delete m_workingMetadata;
00058 }
00059 
00060 bool EditMetadataDialog::Create()
00061 {
00062     if (!LoadWindowFromXML("video-ui.xml", "edit_metadata", this))
00063         return false;
00064 
00065     bool err = false;
00066     UIUtilE::Assign(this, m_titleEdit, "title_edit", &err);
00067     UIUtilE::Assign(this, m_subtitleEdit, "subtitle_edit", &err);
00068     UIUtilE::Assign(this, m_playerEdit, "player_edit", &err);
00069 
00070     UIUtilE::Assign(this, m_seasonSpin, "season", &err);
00071     UIUtilE::Assign(this, m_episodeSpin, "episode", &err);
00072 
00073 
00074     UIUtilE::Assign(this, m_categoryList, "category_select", &err);
00075     UIUtilE::Assign(this, m_levelList, "level_select", &err);
00076     UIUtilE::Assign(this, m_childList, "child_select", &err);
00077 
00078     UIUtilE::Assign(this, m_browseCheck, "browse_check", &err);
00079     UIUtilE::Assign(this, m_watchedCheck, "watched_check", &err);
00080 
00081     UIUtilE::Assign(this, m_doneButton, "done_button", &err);
00082 
00083     if (err)
00084     {
00085         LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'edit_metadata'");
00086         return false;
00087     }
00088 
00089     UIUtilW::Assign(this, m_coverartText, "coverart_text");
00090     UIUtilW::Assign(this, m_screenshotText, "screenshot_text");
00091     UIUtilW::Assign(this, m_bannerText, "banner_text");
00092     UIUtilW::Assign(this, m_fanartText, "fanart_text");
00093     UIUtilW::Assign(this, m_trailerText, "trailer_text");
00094 
00095     UIUtilW::Assign(this, m_coverartButton, "coverart_button");
00096     UIUtilW::Assign(this, m_bannerButton, "banner_button");
00097     UIUtilW::Assign(this, m_fanartButton, "fanart_button");
00098     UIUtilW::Assign(this, m_screenshotButton, "screenshot_button");
00099     UIUtilW::Assign(this, m_trailerButton, "trailer_button");
00100 
00101     UIUtilW::Assign(this, m_netBannerButton, "net_banner_button");
00102     UIUtilW::Assign(this, m_netFanartButton, "net_fanart_button");
00103     UIUtilW::Assign(this, m_netScreenshotButton, "net_screenshot_button");
00104     UIUtilW::Assign(this, m_netCoverartButton, "net_coverart_button");
00105 
00106     UIUtilW::Assign(this, m_taglineEdit, "tagline_edit");
00107     UIUtilW::Assign(this, m_ratingEdit, "rating_edit");
00108     UIUtilW::Assign(this, m_directorEdit, "director_edit");
00109     UIUtilW::Assign(this, m_inetrefEdit, "inetref_edit");
00110     UIUtilW::Assign(this, m_homepageEdit, "homepage_edit");
00111     UIUtilW::Assign(this, m_plotEdit, "description_edit");
00112     UIUtilW::Assign(this, m_yearSpin, "year_spin");
00113     UIUtilW::Assign(this, m_userRatingSpin, "userrating_spin");
00114     UIUtilW::Assign(this, m_lengthSpin, "length_spin");
00115 
00116     UIUtilW::Assign(this, m_coverart, "coverart");
00117     UIUtilW::Assign(this, m_screenshot, "screenshot");
00118     UIUtilW::Assign(this, m_banner, "banner");
00119     UIUtilW::Assign(this, m_fanart, "fanart");
00120 
00121     fillWidgets();
00122 
00123     BuildFocusList();
00124 
00125     connect(m_titleEdit, SIGNAL(valueChanged()), SLOT(SetTitle()));
00126     m_titleEdit->SetMaxLength(128);
00127     connect(m_subtitleEdit, SIGNAL(valueChanged()), SLOT(SetSubtitle()));
00128     m_subtitleEdit->SetMaxLength(0);
00129     connect(m_playerEdit, SIGNAL(valueChanged()), SLOT(SetPlayer()));
00130     if (m_taglineEdit)
00131     {
00132         connect(m_taglineEdit, SIGNAL(valueChanged()), SLOT(SetTagline()));
00133         m_taglineEdit->SetMaxLength(255);
00134     }
00135     if (m_ratingEdit)
00136     {
00137         connect(m_ratingEdit, SIGNAL(valueChanged()), SLOT(SetRating()));
00138         m_ratingEdit->SetMaxLength(128);
00139     }
00140     if (m_directorEdit)
00141     {
00142         connect(m_directorEdit, SIGNAL(valueChanged()), SLOT(SetDirector()));
00143         m_directorEdit->SetMaxLength(128);
00144     }
00145     if (m_inetrefEdit)
00146         connect(m_inetrefEdit, SIGNAL(valueChanged()), SLOT(SetInetRef()));
00147     if (m_homepageEdit)
00148     {
00149         connect(m_homepageEdit, SIGNAL(valueChanged()), SLOT(SetHomepage()));
00150         m_homepageEdit->SetMaxLength(0);
00151     }
00152     if (m_plotEdit)
00153     {
00154         connect(m_plotEdit, SIGNAL(valueChanged()), SLOT(SetPlot()));
00155         m_plotEdit->SetMaxLength(0);
00156     }
00157 
00158     connect(m_seasonSpin, SIGNAL(LosingFocus()), SLOT(SetSeason()));
00159     connect(m_episodeSpin, SIGNAL(LosingFocus()), SLOT(SetEpisode()));
00160     if (m_yearSpin)
00161         connect(m_yearSpin, SIGNAL(LosingFocus()), SLOT(SetYear()));
00162     if (m_userRatingSpin)
00163         connect(m_userRatingSpin, SIGNAL(LosingFocus()), SLOT(SetUserRating()));
00164     if (m_lengthSpin)
00165         connect(m_lengthSpin, SIGNAL(LosingFocus()), SLOT(SetLength()));
00166 
00167     connect(m_doneButton, SIGNAL(Clicked()), SLOT(SaveAndExit()));
00168 
00169     // Find Artwork locally
00170     if (m_coverartButton)
00171         connect(m_coverartButton, SIGNAL(Clicked()), SLOT(FindCoverArt()));
00172     if (m_bannerButton)
00173         connect(m_bannerButton, SIGNAL(Clicked()), SLOT(FindBanner()));
00174     if (m_fanartButton)
00175         connect(m_fanartButton, SIGNAL(Clicked()), SLOT(FindFanart()));
00176     if (m_screenshotButton)
00177         connect(m_screenshotButton, SIGNAL(Clicked()), SLOT(FindScreenshot()));
00178 
00179     // Find Artwork on the Internet
00180     if (m_netCoverartButton)
00181         connect(m_netCoverartButton, SIGNAL(Clicked()), SLOT(FindNetCoverArt()));
00182     if (m_netBannerButton)
00183         connect(m_netBannerButton, SIGNAL(Clicked()), SLOT(FindNetBanner()));
00184     if (m_netFanartButton)
00185         connect(m_netFanartButton, SIGNAL(Clicked()), SLOT(FindNetFanart()));
00186     if (m_netScreenshotButton)
00187         connect(m_netScreenshotButton, SIGNAL(Clicked()), SLOT(FindNetScreenshot()));
00188 
00189     if (m_trailerButton)
00190         connect(m_trailerButton, SIGNAL(Clicked()), SLOT(FindTrailer()));
00191 
00192     connect(m_browseCheck, SIGNAL(valueChanged()), SLOT(ToggleBrowse()));
00193     connect(m_watchedCheck, SIGNAL(valueChanged()), SLOT(ToggleWatched()));
00194 
00195     connect(m_childList, SIGNAL(itemSelected(MythUIButtonListItem*)),
00196             SLOT(SetChild(MythUIButtonListItem*)));
00197     connect(m_levelList, SIGNAL(itemSelected(MythUIButtonListItem*)),
00198             SLOT(SetLevel(MythUIButtonListItem*)));
00199     connect(m_categoryList, SIGNAL(itemSelected(MythUIButtonListItem*)),
00200             SLOT(SetCategory(MythUIButtonListItem*)));
00201     connect(m_categoryList, SIGNAL(itemClicked(MythUIButtonListItem*)),
00202             SLOT(NewCategoryPopup()));
00203 
00204     return true;
00205 }
00206 
00207 namespace
00208 {
00209     template <typename T>
00210     struct title_sort
00211     {
00212         bool operator()(const T &lhs, const T &rhs)
00213         {
00214             return QString::localeAwareCompare(lhs.second, rhs.second) < 0;
00215         }
00216     };
00217 
00218     QStringList GetSupportedImageExtensionFilter()
00219     {
00220         QStringList ret;
00221 
00222         QList<QByteArray> exts = QImageReader::supportedImageFormats();
00223         for (QList<QByteArray>::iterator p = exts.begin(); p != exts.end(); ++p)
00224         {
00225             ret.append(QString("*.").append(*p));
00226         }
00227 
00228         return ret;
00229     }
00230 
00231     void FindImagePopup(const QString &prefix, const QString &prefixAlt,
00232             QObject &inst, const QString &returnEvent)
00233     {
00234         QString fp;
00235 
00236         if (prefix.startsWith("myth://"))
00237             fp = prefix;
00238         else
00239             fp = prefix.isEmpty() ? prefixAlt : prefix;
00240 
00241         MythScreenStack *popupStack =
00242                 GetMythMainWindow()->GetStack("popup stack");
00243 
00244         MythUIFileBrowser *fb = new MythUIFileBrowser(popupStack, fp);
00245         fb->SetNameFilter(GetSupportedImageExtensionFilter());
00246         if (fb->Create())
00247         {
00248             fb->SetReturnEvent(&inst, returnEvent);
00249             popupStack->AddScreen(fb);
00250         }
00251         else
00252             delete fb;
00253     }
00254 
00255     void FindVideoFilePopup(const QString &prefix, const QString &prefixAlt,
00256             QObject &inst, const QString &returnEvent)
00257     {
00258         QString fp;
00259 
00260         if (prefix.startsWith("myth://"))
00261             fp = prefix;
00262         else
00263             fp = prefix.isEmpty() ? prefixAlt : prefix;
00264 
00265         MythScreenStack *popupStack =
00266                 GetMythMainWindow()->GetStack("popup stack");
00267         QStringList exts;
00268 
00269         const FileAssociations::association_list fa_list =
00270                 FileAssociations::getFileAssociation().getList();
00271         for (FileAssociations::association_list::const_iterator p =
00272                 fa_list.begin(); p != fa_list.end(); ++p)
00273         {
00274             exts << QString("*.%1").arg(p->extension.toUpper());
00275         }
00276 
00277         MythUIFileBrowser *fb = new MythUIFileBrowser(popupStack, fp);
00278         fb->SetNameFilter(exts);
00279         if (fb->Create())
00280         {
00281             fb->SetReturnEvent(&inst, returnEvent);
00282             popupStack->AddScreen(fb);
00283         }
00284         else
00285             delete fb;
00286     }
00287 
00288     const QString CEID_COVERARTFILE = "coverartfile";
00289     const QString CEID_BANNERFILE = "bannerfile";
00290     const QString CEID_FANARTFILE = "fanartfile";
00291     const QString CEID_SCREENSHOTFILE = "screenshotfile";
00292     const QString CEID_TRAILERFILE = "trailerfile";
00293     const QString CEID_NEWCATEGORY = "newcategory";
00294 }
00295 
00296 void EditMetadataDialog::createBusyDialog(QString title)
00297 {
00298     if (m_busyPopup)
00299         return;
00300 
00301     QString message = title;
00302 
00303     m_busyPopup = new MythUIBusyDialog(message, m_popupStack,
00304             "mythvideobusydialog");
00305 
00306     if (m_busyPopup->Create())
00307         m_popupStack->AddScreen(m_busyPopup);
00308 }
00309 
00310 void EditMetadataDialog::fillWidgets()
00311 {
00312     m_titleEdit->SetText(m_workingMetadata->GetTitle());
00313     m_subtitleEdit->SetText(m_workingMetadata->GetSubtitle());
00314 
00315     m_seasonSpin->SetRange(0,9999,1,5);
00316     m_seasonSpin->SetValue(m_workingMetadata->GetSeason());
00317     m_episodeSpin->SetRange(0,999,1,10);
00318     m_episodeSpin->SetValue(m_workingMetadata->GetEpisode());
00319     if (m_yearSpin)
00320     {
00321         m_yearSpin->SetRange(0,9999,1,10);
00322         m_yearSpin->SetValue(m_workingMetadata->GetYear());
00323     }
00324     if (m_userRatingSpin)
00325     {
00326         m_userRatingSpin->SetRange(0,10,1,2);
00327         m_userRatingSpin->SetValue(m_workingMetadata->GetUserRating());
00328     }
00329     if (m_lengthSpin)
00330     {
00331         m_lengthSpin->SetRange(0,999,1,15);
00332         m_lengthSpin->SetValue(m_workingMetadata->GetLength());
00333     }
00334 
00335     MythUIButtonListItem *button =
00336         new MythUIButtonListItem(m_categoryList, VIDEO_CATEGORY_UNKNOWN);
00337     const VideoCategory::entry_list &vcl =
00338             VideoCategory::GetCategory().getList();
00339     for (VideoCategory::entry_list::const_iterator p = vcl.begin();
00340             p != vcl.end(); ++p)
00341     {
00342         button = new MythUIButtonListItem(m_categoryList, p->second);
00343         button->SetData(p->first);
00344     }
00345     m_categoryList->SetValueByData(m_workingMetadata->GetCategoryID());
00346 
00347     for (ParentalLevel i = ParentalLevel::plLowest;
00348             i <= ParentalLevel::plHigh && i.good(); ++i)
00349     {
00350         button = new MythUIButtonListItem(m_levelList,
00351                                     QString(tr("Level %1")).arg(i.GetLevel()));
00352         button->SetData(i.GetLevel());
00353     }
00354     m_levelList->SetValueByData(m_workingMetadata->GetShowLevel());
00355 
00356     //
00357     //  Fill the "always play this video next" option
00358     //  with all available videos.
00359     //
00360 
00361     button = new MythUIButtonListItem(m_childList,tr("None"));
00362 
00363     // TODO: maybe make the title list have the same sort order
00364     // as elsewhere.
00365     typedef std::vector<std::pair<unsigned int, QString> > title_list;
00366     const VideoMetadataListManager::metadata_list &mdl = m_metaCache.getList();
00367     title_list tc;
00368     tc.reserve(mdl.size());
00369     for (VideoMetadataListManager::metadata_list::const_iterator p = mdl.begin();
00370             p != mdl.end(); ++p)
00371     {
00372         QString title;
00373         if ((*p)->GetSeason() > 0 || (*p)->GetEpisode() > 0)
00374             title = QString("%1 %2x%3").arg((*p)->GetTitle())
00375                                        .arg(QString::number((*p)->GetSeason()))
00376                                        .arg(QString::number((*p)->GetEpisode()));
00377         else
00378             title = (*p)->GetTitle();
00379         tc.push_back(std::make_pair((*p)->GetID(), title));
00380     }
00381     std::sort(tc.begin(), tc.end(), title_sort<title_list::value_type>());
00382 
00383     for (title_list::const_iterator p = tc.begin(); p != tc.end(); ++p)
00384     {
00385         if (p->first != m_workingMetadata->GetID())
00386         {
00387             button = new MythUIButtonListItem(m_childList,p->second);
00388             button->SetData(p->first);
00389         }
00390     }
00391 
00392     if (m_workingMetadata->GetChildID() > 0)
00393     {
00394         m_childList->SetValueByData(m_workingMetadata->GetChildID());
00395         cachedChildSelection = m_workingMetadata->GetChildID();
00396     }
00397 
00398     if (m_workingMetadata->GetBrowse())
00399         m_browseCheck->SetCheckState(MythUIStateType::Full);
00400     if (m_workingMetadata->GetWatched())
00401         m_watchedCheck->SetCheckState(MythUIStateType::Full);
00402     if (m_coverartText)
00403         m_coverartText->SetText(m_workingMetadata->GetCoverFile());
00404     if (m_screenshotText)
00405         m_screenshotText->SetText(m_workingMetadata->GetScreenshot());
00406     if (m_bannerText)
00407         m_bannerText->SetText(m_workingMetadata->GetBanner());
00408     if (m_fanartText)
00409         m_fanartText->SetText(m_workingMetadata->GetFanart());
00410     if (m_trailerText)
00411         m_trailerText->SetText(m_workingMetadata->GetTrailer());
00412 
00413     m_playerEdit->SetText(m_workingMetadata->GetPlayCommand());
00414     if (m_taglineEdit)
00415         m_taglineEdit->SetText(m_workingMetadata->GetTagline());
00416     if (m_ratingEdit)
00417         m_ratingEdit->SetText(m_workingMetadata->GetRating());
00418     if (m_directorEdit)
00419         m_directorEdit->SetText(m_workingMetadata->GetDirector());
00420     if (m_inetrefEdit)
00421         m_inetrefEdit->SetText(m_workingMetadata->GetInetRef());
00422     if (m_homepageEdit)
00423         m_homepageEdit->SetText(m_workingMetadata->GetHomepage());
00424     if (m_plotEdit)
00425         m_plotEdit->SetText(m_workingMetadata->GetPlot());
00426 
00427     if (m_coverart)
00428     {
00429         if (!m_workingMetadata->GetHost().isEmpty() &&
00430             !m_workingMetadata->GetCoverFile().isEmpty() &&
00431             !m_workingMetadata->GetCoverFile().startsWith("/"))
00432         {
00433             m_coverart->SetFilename(generate_file_url("Coverart",
00434                                   m_workingMetadata->GetHost(),
00435                                   m_workingMetadata->GetCoverFile()));
00436         }
00437         else
00438             m_coverart->SetFilename(m_workingMetadata->GetCoverFile());
00439 
00440         if (!m_workingMetadata->GetCoverFile().isEmpty())
00441             m_coverart->Load();
00442     }
00443     if (m_screenshot)
00444     {
00445         if (!m_workingMetadata->GetHost().isEmpty() &&
00446             !m_workingMetadata->GetScreenshot().isEmpty() &&
00447             !m_workingMetadata->GetScreenshot().startsWith("/"))
00448         {
00449             m_screenshot->SetFilename(generate_file_url("Screenshots",
00450                                   m_workingMetadata->GetHost(),
00451                                   m_workingMetadata->GetScreenshot()));
00452         }
00453         else
00454             m_screenshot->SetFilename(m_workingMetadata->GetScreenshot());
00455 
00456         if (!m_workingMetadata->GetScreenshot().isEmpty())
00457             m_screenshot->Load();
00458     }
00459     if (m_banner)
00460     {
00461         if (!m_workingMetadata->GetHost().isEmpty() &&
00462             !m_workingMetadata->GetBanner().isEmpty() &&
00463             !m_workingMetadata->GetBanner().startsWith("/"))
00464         {
00465             m_banner->SetFilename(generate_file_url("Banners",
00466                                   m_workingMetadata->GetHost(),
00467                                   m_workingMetadata->GetBanner()));
00468         }
00469         else
00470             m_banner->SetFilename(m_workingMetadata->GetBanner());
00471 
00472         if (!m_workingMetadata->GetBanner().isEmpty())
00473             m_banner->Load();
00474     }
00475     if (m_fanart)
00476     {
00477         if (!m_workingMetadata->GetHost().isEmpty() &&
00478             !m_workingMetadata->GetFanart().isEmpty() &&
00479             !m_workingMetadata->GetFanart().startsWith("/"))
00480         {
00481             m_fanart->SetFilename(generate_file_url("Fanart",
00482                                   m_workingMetadata->GetHost(),
00483                                   m_workingMetadata->GetFanart()));
00484         }
00485         else
00486             m_fanart->SetFilename(m_workingMetadata->GetFanart());
00487 
00488         if (!m_workingMetadata->GetFanart().isEmpty())
00489             m_fanart->Load();
00490     }
00491 }
00492 
00493 void EditMetadataDialog::NewCategoryPopup()
00494 {
00495     QString message = tr("Enter new category");
00496 
00497     MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00498 
00499     MythTextInputDialog *categorydialog =
00500                                     new MythTextInputDialog(popupStack,message);
00501 
00502     if (categorydialog->Create())
00503     {
00504         categorydialog->SetReturnEvent(this, CEID_NEWCATEGORY);
00505         popupStack->AddScreen(categorydialog);
00506     }
00507 
00508 }
00509 
00510 void EditMetadataDialog::AddCategory(QString category)
00511 {
00512     int id = VideoCategory::GetCategory().add(category);
00513     m_workingMetadata->SetCategoryID(id);
00514     new MythUIButtonListItem(m_categoryList, category, id);
00515     m_categoryList->SetValueByData(id);
00516 }
00517 
00518 void EditMetadataDialog::SaveAndExit()
00519 {
00520     *m_origMetadata = *m_workingMetadata;
00521     m_origMetadata->UpdateDatabase();
00522 
00523     emit Finished();
00524     Close();
00525 }
00526 
00527 void EditMetadataDialog::SetTitle()
00528 {
00529     m_workingMetadata->SetTitle(m_titleEdit->GetText());
00530 }
00531 
00532 void EditMetadataDialog::SetSubtitle()
00533 {
00534     m_workingMetadata->SetSubtitle(m_subtitleEdit->GetText());
00535 }
00536 
00537 void EditMetadataDialog::SetCategory(MythUIButtonListItem *item)
00538 {
00539     m_workingMetadata->SetCategoryID(item->GetData().toInt());
00540 }
00541 
00542 void EditMetadataDialog::SetRating()
00543 {
00544     m_workingMetadata->SetRating(m_ratingEdit->GetText());
00545 }
00546 
00547 void EditMetadataDialog::SetTagline()
00548 {
00549     m_workingMetadata->SetTagline(m_taglineEdit->GetText());
00550 }
00551 
00552 void EditMetadataDialog::SetDirector()
00553 {
00554     m_workingMetadata->SetDirector(m_directorEdit->GetText());
00555 }
00556 
00557 void EditMetadataDialog::SetInetRef()
00558 {
00559     m_workingMetadata->SetInetRef(m_inetrefEdit->GetText());
00560 }
00561 
00562 void EditMetadataDialog::SetHomepage()
00563 {
00564     m_workingMetadata->SetHomepage(m_homepageEdit->GetText());
00565 }
00566 
00567 void EditMetadataDialog::SetPlot()
00568 {
00569     m_workingMetadata->SetPlot(m_plotEdit->GetText());
00570 }
00571 
00572 void EditMetadataDialog::SetSeason()
00573 {
00574     m_workingMetadata->SetSeason(m_seasonSpin->GetIntValue());
00575 }
00576 
00577 void EditMetadataDialog::SetEpisode()
00578 {
00579     m_workingMetadata->SetEpisode(m_episodeSpin->GetIntValue());
00580 }
00581 
00582 void EditMetadataDialog::SetYear()
00583 {
00584     m_workingMetadata->SetYear(m_yearSpin->GetIntValue());
00585 }
00586 
00587 void EditMetadataDialog::SetUserRating()
00588 {
00589     m_workingMetadata->SetUserRating(m_userRatingSpin->GetIntValue());
00590 }
00591 
00592 void EditMetadataDialog::SetLength()
00593 {
00594     m_workingMetadata->SetLength(m_lengthSpin->GetIntValue());
00595 }
00596 
00597 void EditMetadataDialog::SetPlayer()
00598 {
00599     m_workingMetadata->SetPlayCommand(m_playerEdit->GetText());
00600 }
00601 
00602 void EditMetadataDialog::SetLevel(MythUIButtonListItem *item)
00603 {
00604     m_workingMetadata->
00605             SetShowLevel(ParentalLevel(item->GetData().toInt()).GetLevel());
00606 }
00607 
00608 void EditMetadataDialog::SetChild(MythUIButtonListItem *item)
00609 {
00610     cachedChildSelection = item->GetData().toInt();
00611     m_workingMetadata->SetChildID(cachedChildSelection);
00612 }
00613 
00614 void EditMetadataDialog::ToggleBrowse()
00615 {
00616     m_workingMetadata->
00617             SetBrowse(m_browseCheck->GetBooleanCheckState());
00618 }
00619 
00620 void EditMetadataDialog::ToggleWatched()
00621 {
00622     m_workingMetadata->
00623             SetWatched(m_watchedCheck->GetBooleanCheckState());
00624 }
00625 
00626 void EditMetadataDialog::FindCoverArt()
00627 {
00628     if (!m_workingMetadata->GetHost().isEmpty())
00629     {
00630         QString url = generate_file_url("Coverart",
00631                       m_workingMetadata->GetHost(),
00632                       "");
00633         FindImagePopup(url,"",
00634                        *this, CEID_COVERARTFILE);
00635     }
00636     else
00637         FindImagePopup(gCoreContext->GetSetting("VideoArtworkDir"),
00638                 GetConfDir() + "/MythVideo",
00639                 *this, CEID_COVERARTFILE);
00640 }
00641 
00642 void EditMetadataDialog::OnArtworkSearchDone(MetadataLookup *lookup)
00643 {
00644     if (!lookup)
00645         return;
00646 
00647     if (m_busyPopup)
00648     {
00649         m_busyPopup->Close();
00650         m_busyPopup = NULL;
00651     }
00652 
00653     VideoArtworkType type = qVariantValue<VideoArtworkType>(lookup->GetData());
00654     ArtworkList list = lookup->GetArtwork(type);
00655 
00656     if (list.count() == 0)
00657         return;
00658 
00659     MythScreenStack *m_popupStack =
00660                      GetMythMainWindow()->GetStack("popup stack");
00661 
00662     ImageSearchResultsDialog *resultsdialog =
00663           new ImageSearchResultsDialog(m_popupStack, list, type);
00664 
00665     connect(resultsdialog, SIGNAL(haveResult(ArtworkInfo, VideoArtworkType)),
00666             SLOT(OnSearchListSelection(ArtworkInfo, VideoArtworkType)));
00667 
00668     if (resultsdialog->Create())
00669         m_popupStack->AddScreen(resultsdialog);
00670 }
00671 
00672 void EditMetadataDialog::OnSearchListSelection(ArtworkInfo info, VideoArtworkType type)
00673 {
00674     QString msg = tr("Downloading selected artwork...");
00675     createBusyDialog(msg);
00676 
00677     MetadataLookup *lookup = new MetadataLookup();
00678     lookup->SetType(kMetadataVideo);
00679     if (m_workingMetadata->GetSeason() > 0 ||
00680             m_workingMetadata->GetEpisode() > 0)
00681         lookup->SetSubtype(kProbableTelevision);
00682     else if (m_workingMetadata->GetSubtitle().isEmpty())
00683         lookup->SetSubtype(kProbableMovie);
00684     else
00685         lookup->SetSubtype(kUnknownVideo);
00686     lookup->SetHost(m_workingMetadata->GetHost());
00687     lookup->SetAutomatic(true);
00688     lookup->SetData(qVariantFromValue<VideoArtworkType>(type));
00689 
00690     ArtworkMap downloads;
00691     downloads.insert(type, info);
00692     lookup->SetDownloads(downloads);
00693     lookup->SetAllowOverwrites(true);
00694     lookup->SetTitle(m_workingMetadata->GetTitle());
00695     lookup->SetSubtitle(m_workingMetadata->GetSubtitle());
00696     lookup->SetSeason(m_workingMetadata->GetSeason());
00697     lookup->SetEpisode(m_workingMetadata->GetEpisode());
00698     lookup->SetInetref(m_workingMetadata->GetInetRef());
00699 
00700     m_imageDownload->addDownloads(lookup);
00701 }
00702 
00703 void EditMetadataDialog::handleDownloadedImages(MetadataLookup *lookup)
00704 {
00705     if (!lookup)
00706         return;
00707 
00708     if (m_busyPopup)
00709     {
00710         m_busyPopup->Close();
00711         m_busyPopup = NULL;
00712     }
00713 
00714     VideoArtworkType type = qVariantValue<VideoArtworkType>(lookup->GetData());
00715     ArtworkMap map = lookup->GetDownloads();
00716 
00717     if (map.count() >= 1)
00718     {
00719         ArtworkInfo info = map.value(type);
00720         QString filename = info.url;
00721 
00722         if (type == kArtworkCoverart)
00723             SetCoverArt(filename);
00724         else if (type == kArtworkFanart)
00725             SetFanart(filename);
00726         else if (type == kArtworkBanner)
00727             SetBanner(filename);
00728         else if (type == kArtworkScreenshot)
00729             SetScreenshot(filename);
00730     }
00731 }
00732 
00733 void EditMetadataDialog::FindNetArt(VideoArtworkType type)
00734 {
00735     QString msg = tr("Searching for available artwork...");
00736     createBusyDialog(msg);
00737 
00738     MetadataLookup *lookup = new MetadataLookup();
00739     lookup->SetStep(kLookupSearch);
00740     lookup->SetType(kMetadataVideo);
00741     lookup->SetAutomatic(true);
00742     if (m_workingMetadata->GetSeason() > 0 ||
00743             m_workingMetadata->GetEpisode() > 0)
00744         lookup->SetSubtype(kProbableTelevision);
00745     else if (m_workingMetadata->GetSubtitle().isEmpty())
00746         lookup->SetSubtype(kProbableMovie);
00747     else
00748         lookup->SetSubtype(kUnknownVideo);
00749     lookup->SetData(qVariantFromValue<VideoArtworkType>(type));
00750 
00751     lookup->SetTitle(m_workingMetadata->GetTitle());
00752     lookup->SetSubtitle(m_workingMetadata->GetSubtitle());
00753     lookup->SetSeason(m_workingMetadata->GetSeason());
00754     lookup->SetEpisode(m_workingMetadata->GetEpisode());
00755     lookup->SetInetref(m_workingMetadata->GetInetRef());
00756 
00757     m_query->addLookup(lookup);
00758 }
00759 
00760 void EditMetadataDialog::FindNetCoverArt()
00761 {
00762     FindNetArt(kArtworkCoverart);
00763 }
00764 
00765 void EditMetadataDialog::FindNetFanart()
00766 {
00767     FindNetArt(kArtworkFanart);
00768 }
00769 
00770 void EditMetadataDialog::FindNetBanner()
00771 {
00772     FindNetArt(kArtworkBanner);
00773 }
00774 
00775 void EditMetadataDialog::FindNetScreenshot()
00776 {
00777     FindNetArt(kArtworkScreenshot);
00778 }
00779 
00780 void EditMetadataDialog::SetCoverArt(QString file)
00781 {
00782     if (file.isEmpty())
00783         return;
00784 
00785     QString origfile = file;
00786 
00787     if (file.startsWith("myth://"))
00788     {
00789         QUrl url(file);
00790         file = url.path();
00791         file = file.right(file.length() - 1);
00792         if (!file.endsWith("/"))
00793             m_workingMetadata->SetCoverFile(file);
00794         else
00795             m_workingMetadata->SetCoverFile(QString());
00796     }
00797     else
00798         m_workingMetadata->SetCoverFile(file);
00799 
00800     CheckedSet(m_coverartText, file);
00801 
00802     if (m_coverart)
00803     {
00804         m_coverart->SetFilename(origfile);
00805         m_coverart->Load();
00806     }
00807 }
00808 
00809 void EditMetadataDialog::FindBanner()
00810 {
00811     if (!m_workingMetadata->GetHost().isEmpty())
00812     {
00813         QString url = generate_file_url("Banners",
00814                       m_workingMetadata->GetHost(),
00815                       "");
00816         FindImagePopup(url,"",
00817                 *this, CEID_BANNERFILE);
00818     }
00819     else
00820         FindImagePopup(gCoreContext->GetSetting("mythvideo.bannerDir"),
00821                 GetConfDir() + "/MythVideo/Banners",
00822                 *this, CEID_BANNERFILE);
00823 }
00824 
00825 void EditMetadataDialog::SetBanner(QString file)
00826 {
00827     if (file.isEmpty())
00828         return;
00829 
00830     QString origfile = file;
00831 
00832     if (file.startsWith("myth://"))
00833     {
00834         QUrl url(file);
00835         file = url.path();
00836         file = file.right(file.length() - 1);
00837         if (!file.endsWith("/"))
00838             m_workingMetadata->SetBanner(file);
00839         else
00840             m_workingMetadata->SetBanner(QString());
00841     }
00842     else
00843         m_workingMetadata->SetBanner(file);
00844 
00845     CheckedSet(m_bannerText, file);
00846 
00847     if (m_banner)
00848     {
00849         m_banner->SetFilename(origfile);
00850         m_banner->Load();
00851     }
00852 }
00853 
00854 void EditMetadataDialog::FindFanart()
00855 {
00856     if (!m_workingMetadata->GetHost().isEmpty())
00857     {
00858         QString url = generate_file_url("Fanart",
00859                       m_workingMetadata->GetHost(),
00860                       "");
00861         FindImagePopup(url,"",
00862                 *this, CEID_FANARTFILE);
00863     }
00864     else
00865         FindImagePopup(gCoreContext->GetSetting("mythvideo.fanartDir"),
00866                 GetConfDir() + "/MythVideo/Fanart",
00867                 *this, CEID_FANARTFILE);
00868 }
00869 
00870 void EditMetadataDialog::SetFanart(QString file)
00871 {
00872     if (file.isEmpty())
00873         return;
00874 
00875     QString origfile = file;
00876 
00877     if (file.startsWith("myth://"))
00878     {
00879         QUrl url(file);
00880         file = url.path();
00881         file = file.right(file.length() - 1);
00882         if (!file.endsWith("/"))
00883             m_workingMetadata->SetFanart(file);
00884         else
00885             m_workingMetadata->SetFanart(QString());
00886     }
00887     else
00888         m_workingMetadata->SetFanart(file);
00889 
00890     CheckedSet(m_fanartText, file);
00891 
00892     if (m_fanart)
00893     {
00894         m_fanart->SetFilename(origfile);
00895         m_fanart->Load();
00896     }
00897 }
00898 
00899 void EditMetadataDialog::FindScreenshot()
00900 {
00901     if (!m_workingMetadata->GetHost().isEmpty())
00902     {
00903         QString url = generate_file_url("Screenshots",
00904                       m_workingMetadata->GetHost(),
00905                       "");
00906         FindImagePopup(url,"",
00907                 *this, CEID_SCREENSHOTFILE);
00908     }
00909     else
00910         FindImagePopup(gCoreContext->GetSetting("mythvideo.screenshotDir"),
00911                 GetConfDir() + "/MythVideo/Screenshots",
00912                 *this, CEID_SCREENSHOTFILE);
00913 }
00914 
00915 void EditMetadataDialog::SetScreenshot(QString file)
00916 {
00917     if (file.isEmpty())
00918         return;
00919 
00920     QString origfile = file;
00921 
00922     if (file.startsWith("myth://"))
00923     {
00924         QUrl url(file);
00925         file = url.path();
00926         file = file.right(file.length() - 1);
00927         if (!file.endsWith("/"))
00928             m_workingMetadata->SetScreenshot(file);
00929         else
00930             m_workingMetadata->SetScreenshot(QString());
00931     }
00932     else
00933         m_workingMetadata->SetScreenshot(file);
00934 
00935     CheckedSet(m_screenshotText, file);
00936 
00937     if (m_screenshot)
00938     {
00939         m_screenshot->SetFilename(origfile);
00940         m_screenshot->Load();
00941     }
00942 }
00943 
00944 void EditMetadataDialog::FindTrailer()
00945 {
00946     if (!m_workingMetadata->GetHost().isEmpty())
00947     {
00948         QString url = generate_file_url("Trailers",
00949                       m_workingMetadata->GetHost(),
00950                       "");
00951         FindVideoFilePopup(url,"",
00952                 *this, CEID_TRAILERFILE);
00953     }
00954     else
00955         FindVideoFilePopup(gCoreContext->GetSetting("mythvideo.TrailersDir"),
00956                 GetConfDir() + "/MythVideo/Trailers",
00957                 *this, CEID_TRAILERFILE);
00958 }
00959 
00960 void EditMetadataDialog::SetTrailer(QString file)
00961 {
00962     if (file.isEmpty())
00963         return;
00964 
00965     if (file.startsWith("myth://"))
00966     {
00967         QUrl url(file);
00968         file = url.path();
00969         file = file.right(file.length() - 1);
00970         if (!file.endsWith("/"))
00971             m_workingMetadata->SetTrailer(file);
00972         else
00973             m_workingMetadata->SetTrailer(QString());
00974     }
00975     else
00976         m_workingMetadata->SetTrailer(file);
00977     CheckedSet(m_trailerText, file);
00978 }
00979 
00980 void EditMetadataDialog::customEvent(QEvent *levent)
00981 {
00982     if (levent->type() == DialogCompletionEvent::kEventType)
00983     {
00984         DialogCompletionEvent *dce = (DialogCompletionEvent*)(levent);
00985 
00986         const QString resultid = dce->GetId();
00987 
00988         if (resultid == CEID_COVERARTFILE)
00989             SetCoverArt(dce->GetResultText());
00990         else if (resultid == CEID_BANNERFILE)
00991             SetBanner(dce->GetResultText());
00992         else if (resultid == CEID_FANARTFILE)
00993             SetFanart(dce->GetResultText());
00994         else if (resultid == CEID_SCREENSHOTFILE)
00995             SetScreenshot(dce->GetResultText());
00996         else if (resultid == CEID_TRAILERFILE)
00997             SetTrailer(dce->GetResultText());
00998         else if (resultid == CEID_NEWCATEGORY)
00999             AddCategory(dce->GetResultText());
01000     }
01001     else if (levent->type() == MetadataLookupEvent::kEventType)
01002     {
01003         MetadataLookupEvent *lue = (MetadataLookupEvent *)levent;
01004 
01005         MetadataLookupList lul = lue->lookupList;
01006 
01007         if (lul.isEmpty())
01008             return;
01009 
01010         // There should really only be one result here.
01011         // If not, USER ERROR!
01012         if (lul.count() == 1)
01013         {
01014             OnArtworkSearchDone(lul.takeFirst());
01015         }
01016         else
01017         {
01018             if (m_busyPopup)
01019             {
01020                 m_busyPopup->Close();
01021                 m_busyPopup = NULL;
01022             }
01023         }
01024     }
01025     else if (levent->type() == MetadataLookupFailure::kEventType)
01026     {
01027         MetadataLookupFailure *luf = (MetadataLookupFailure *)levent;
01028 
01029         MetadataLookupList lul = luf->lookupList;
01030 
01031         if (m_busyPopup)
01032         {
01033             m_busyPopup->Close();
01034             m_busyPopup = NULL;
01035         }
01036 
01037         if (lul.size())
01038         {
01039             MetadataLookup *lookup = lul.takeFirst();
01040             LOG(VB_GENERAL, LOG_INFO,
01041                 QString("No results found for %1 %2 %3").arg(lookup->GetTitle())
01042                     .arg(lookup->GetSeason()).arg(lookup->GetEpisode()));
01043         }
01044     }
01045     else if (levent->type() == ImageDLEvent::kEventType)
01046     {
01047         ImageDLEvent *ide = (ImageDLEvent *)levent;
01048 
01049         MetadataLookup *lookup = ide->item;
01050 
01051         if (!lookup)
01052             return;
01053 
01054         handleDownloadedImages(lookup);
01055     }
01056 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends