📄 cdmanager.cpp
字号:
#endif#if (WITH_RECORDS == 1) grpAction->add (apMenus[IMPORT_MP3] = Gtk::Action::create ("Import", _("_Import from file-info ...")), Gtk::AccelKey (_("<ctl>I")), mem_fun (*this, &CDManager::importFromFileInfo));#endif grpAction->add (Gtk::Action::create ("FQuit", Gtk::Stock::QUIT), mem_fun (*this, &CDManager::exit)); grpAction->add (apMenus[MEDIT] = Gtk::Action::create ("Edit", _("_Edit"))); grpAction->add (Gtk::Action::create ("Options", _("_Options"))); grpAction->add (Gtk::Action::create ("Prefs", Gtk::Stock::PREFERENCES), Gtk::AccelKey (_("F9")), mem_fun (*this, &CDManager::editPreferences)); grpAction->add (apMenus[SAVE_PREFS] = Gtk::Action::create ("SavePrefs", _("_Save preferences")), Gtk::AccelKey (_("<ctl>F9")), mem_fun (*this, &CDManager::savePreferences)); addHelpMenu (ui); ui += "</menubar></ui>"; mgrUI->insert_action_group (grpAction); add_accel_group (mgrUI->get_accel_group ()); mgrUI->add_ui_from_string (ui); Check3 (mgrUI->get_widget("/Menu/Help")); ((Gtk::MenuItem*)(mgrUI->get_widget("/Menu/Help")))->set_right_justified (); enableMenus (false); nb.set_show_tabs (WITH_ACTORS + WITH_RECORDS + WITH_MOVIES - 1); getClient ()->pack_start (*mgrUI->get_widget("/Menu"), Gtk::PACK_SHRINK); getClient ()->pack_start (nb, Gtk::PACK_EXPAND_WIDGET); getClient ()->pack_end (status, Gtk::PACK_SHRINK); try { const char* pLang (getenv ("LANGUAGE")); if (!pLang) {#ifdef HAVE_LC_MESSAGES pLang = setlocale (LC_MESSAGES, NULL);#else pLang = getenv ("LANG");#endif } Genres::loadFromFile (DATADIR "Genres.dat", recGenres, movieGenres, pLang); TRACE8 ("Genres: " << recGenres.size () << '/' << movieGenres.size ()); } catch (std::exception& e) { Glib::ustring msg (_("Can't read datafile containing the genres!\n\nReason: %1")); msg.replace (msg.find ("%1"), 2, e.what ()); Gtk::MessageDialog dlg (msg, Gtk::MESSAGE_ERROR); dlg.run (); } if (opt.getUser ().empty () || !login (opt.getUser (), opt.getPassword ())) Glib::signal_idle ().connect (bind_return (mem_fun (*this, &CDManager::showLogin), false)); TRACE8 ("CDManager::CDManager (Options&) - Add NB");#if WITH_RECORDS == 1 NBPage* pgRecords = (new PRecords (status, apMenus[SAVE], recGenres)); pages[0] = pgRecords; nb.append_page (*manage (pgRecords->getWindow ()), _("_Records"), true);#endif#if WITH_MOVIES == 1 PMovies* pgMovies = (new PMovies (status, apMenus[SAVE], movieGenres)); pages[WITH_RECORDS] = pgMovies; nb.append_page (*manage (pgMovies->getWindow ()), _("_Movies"), true);#endif#if WITH_ACTORS == 1 NBPage* pgActor = (new PActors (status, apMenus[SAVE], movieGenres, *pgMovies)); pages[WITH_RECORDS + WITH_MOVIES] = pgActor; nb.append_page (*manage (pgActor->getWindow ()), _("_Actors"), true);#endif nb.signal_switch_page ().connect (mem_fun (*this, &CDManager::pageSwitched), false); status.push (_("Connect to a database ...")); apMenus[SAVE]->set_sensitive (false); TRACE8 ("CDManager::CDManager (Options&) - Show"); show_all_children (); show ();}//-----------------------------------------------------------------------------/// Destructor//-----------------------------------------------------------------------------CDManager::~CDManager () { TRACE8 ("CDManager::~CDManager ()"); for (unsigned int i (0); i < (sizeof (pages) / sizeof (*pages)); ++i) pages[i]->clear ();}//-----------------------------------------------------------------------------/// Saves the DB//-----------------------------------------------------------------------------void CDManager::save () { TRACE9 ("CDManager::save ()"); try { for (unsigned int i (0); i < (sizeof (pages) / sizeof (*pages)); ++i) if (pages[i]->isChanged ()) pages[i]->saveData (); Check3 (apMenus[SAVE]); apMenus[SAVE]->set_sensitive (false); } catch (std::exception& err) { Glib::ustring msg (_("Error saving data!\n\nReason: %1")); msg.replace (msg.find ("%1"), 2, err.what ()); Gtk::MessageDialog dlg (msg, Gtk::MESSAGE_ERROR); dlg.run (); }}#if WITH_RECORDS == 1//-----------------------------------------------------------------------------/// Imports information from audio file (e.g. MP3-ID3 tag or OGG-commentheader)//-----------------------------------------------------------------------------void CDManager::importFromFileInfo () { XGP::FileDialog::create (_("Select file(s) to import"), Gtk::FILE_CHOOSER_ACTION_OPEN, XGP::FileDialog::MUST_EXIST | XGP::FileDialog::MULTIPLE) ->sigSelected.connect (mem_fun (*this, &CDManager::parseFileInfo));}#endif//-----------------------------------------------------------------------------/// Edits the preferences//-----------------------------------------------------------------------------void CDManager::editPreferences () { Settings::create (get_window (), opt);}//-----------------------------------------------------------------------------/// Shows the about box for the program//-----------------------------------------------------------------------------void CDManager::showAboutbox () { std::string ver (_("Copyright (C) 2004 - 2006 Markus Schwab" "\ne-mail: <g17m0@lycos.com>\n\nCompiled on %1 at %2")); ver.replace (ver.find ("%1"), 2, __DATE__); ver.replace (ver.find ("%2"), 2, __TIME__); XGP::XAbout* about (XGP::XAbout::create (ver, PACKAGE " V" VERSION)); about->setIconProgram (xpmProgram); about->setIconAuthor (xpmAuthor); about->get_window ()->set_transient_for (get_window ());}//-----------------------------------------------------------------------------/// Returns the name of the file to display in the help/// \returns \c Name of file to display//-----------------------------------------------------------------------------const char* CDManager::getHelpfile () { return DOCUDIR "CDManager.html";}//-----------------------------------------------------------------------------/// Displays a dialog to login to the database//-----------------------------------------------------------------------------void CDManager::showLogin () { TRACE8 ("CDManager::showLogin ()"); XGP::LoginDialog* dlg (XGP::LoginDialog::create (_("Database login"))); dlg->get_window ()->set_transient_for (get_window ()); dlg->sigLogin.connect (mem_fun (*this, &CDManager::login)); if (opt.getUser ().size ()) dlg->setUser (opt.getUser ()); else dlg->setCurrentUser (); dlg->setPassword (opt.getPassword ());}//-----------------------------------------------------------------------------/// Enables or disables the menus according to the status of the program/// \param enable: Flag, if menus should be enabled//-----------------------------------------------------------------------------void CDManager::enableMenus (bool enable) { apMenus[LOGOUT]->set_sensitive (enable); apMenus[MEDIT]->set_sensitive (enable);#if (WITH_RECORDS == 1) || (WITH_MOVIES == 1) apMenus[EXPORT]->set_sensitive (enable);#endif#if WITH_RECORDS == 1 apMenus[IMPORT_MP3]->set_sensitive (enable);#endif apMenus[SAVE_PREFS]->set_sensitive (enable); nb.set_sensitive (enable); apMenus[LOGIN]->set_sensitive (enable = !enable); apMenus[SAVE]->set_sensitive (false);}//-----------------------------------------------------------------------------/// Loads the database and shows its contents.////// According to the available information the pages of the notebook/// are created.//-----------------------------------------------------------------------------void CDManager::loadDatabase () { TRACE8 ("CDManager::loadDatabase () - " << nb.get_current_page ()); // Check if page is valid (at init the current page can be -1) if ((unsigned int)nb.get_current_page () < (sizeof (pages) / sizeof (*pages))) { status.pop (); status.push (_("Reading database ...")); Check3 (pages[nb.get_current_page ()]); Check3 (!pages[nb.get_current_page ()]->isLoaded ()); pages[nb.get_current_page ()]->loadData (); pages[nb.get_current_page ()]->getFocus (); }}//-----------------------------------------------------------------------------/// Callback when switching the notebook pages/// \param iPage: Index of the newly selected page//-----------------------------------------------------------------------------void CDManager::pageSwitched (GtkNotebookPage*, guint iPage) { TRACE6 ("CDManager::pageSwitched (GtkNotebookPage*, guint) - " << iPage); Check1 (iPage < 3); static Gtk::UIManager::ui_merge_id idPageMrg (-1U); Glib::ustring ui ("<menubar name='Menu'>" " <menu action='Edit'>" " <placeholder name='EditAction'>"); if (nb.get_current_page () != -1) { Check3 (pages[nb.get_current_page ()]); pages[nb.get_current_page ()]->removeMenu (); } if (idPageMrg != -1U) mgrUI->remove_ui (idPageMrg); Check3 (pages[iPage]); if (!pages[iPage]->isLoaded () && Storage::connected ()) pages[iPage]->loadData (); Glib::RefPtr<Gtk::ActionGroup> grpAction (Gtk::ActionGroup::create ()); pages[iPage]->addMenu (ui, grpAction); ui += "</menubar>"; mgrUI->insert_action_group (grpAction); idPageMrg = mgrUI->add_ui_from_string (ui); pages[iPage]->getFocus ();}//-----------------------------------------------------------------------------/// Checks if the DB has been change and asks if it should be safed, before/// hiding (closing) the main window//-----------------------------------------------------------------------------void CDManager::exit () { on_delete_event (NULL); hide ();}//-----------------------------------------------------------------------------/// Checks if the DB has been changed and asks if it should be safed, before/// hiding (closing) the main window/// \param ev: Event/// \returns bool: True, if message has been processed//-----------------------------------------------------------------------------bool CDManager::on_delete_event (GdkEventAny* ev) { for (unsigned int i (0); i < (sizeof (pages) / sizeof (*pages)); ++i) if (pages[i]->isChanged ()) { Gtk::MessageDialog dlg (_("The data has been modified! Save those changes?"), false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); dlg.set_title (PACKAGE); if (dlg.run () == Gtk::RESPONSE_YES) save (); break; } return ev ? XApplication::on_delete_event (ev) : true;}//-----------------------------------------------------------------------------/// Login to the database with the passed user/password pair/// \param user: User to connect to the DB with/// \param pwd: Password for user/// \returns bool: True, if login could be performed//-----------------------------------------------------------------------------bool CDManager::login (const Glib::ustring& user, const Glib::ustring& pwd) { TRACE9 ("CDManager::login (const Glib::ustring&, const Glib::ustring&) - " << user << '/' << pwd); try { Storage::login (DBNAME, user.c_str (), pwd.c_str ()); } catch (std::exception& err) { Glib::ustring msg (_("Can't connect to database!\n\nReason: %1")); msg.replace (msg.find ("%1"), 2, err.what ()); Gtk::MessageDialog dlg (msg, Gtk::MESSAGE_ERROR); dlg.set_title (_("Login error")); dlg.run (); return false; } try { Storage::loadSpecialWords (); TRACE1 ("CDManager::login () - Key: " << Words::getMemoryKey ()); } catch (std::exception& err) { Glib::ustring msg (_("Can't query needed information!\n\nReason: %1")); msg.replace (msg.find ("%1"), 2, err.what ()); Gtk::MessageDialog dlg (msg, Gtk::MESSAGE_ERROR); dlg.run (); } enableMenus (true); loadDatabase ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -