From 283a4201828edde1cf92e59ccbb0395a0f894538 Mon Sep 17 00:00:00 2001 From: LarsAC Date: Fri, 11 Mar 2005 18:18:36 +0000 Subject: Merged changes from 0.1.4-wr git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@565 e10066b5-e1e2-0310-b819-94efdf66514b --- HISTORY | 17 +++++- Makefile | 26 ++++----- mg_mysql.c | 182 ++++++++++++++++++++++++++++++---------------------------- mg_mysql.h | 3 +- mg_sync.c | 4 +- muggle.c | 39 +++++++++---- mugglei.c | 15 +++-- vdr_actions.c | 35 +++++++++-- vdr_menu.c | 17 +++++- vdr_menu.h | 1 + vdr_setup.c | 7 +++ 11 files changed, 215 insertions(+), 131 deletions(-) diff --git a/HISTORY b/HISTORY index 687ff02..d5a168c 100644 --- a/HISTORY +++ b/HISTORY @@ -82,7 +82,6 @@ XXXXXXXXXX: Version 0.0.8-ALPHA - GD compatibility added - Many bugfixes and usability improvements -2005-02-07: Version 0.1.2-BETA - Die Organisation der Dateien kann nun vom Benutzer verändert werden. Zudem können neue Bäume erstellt werden (zB mag ich Decade > Genre > Track sehr gern). @@ -162,3 +161,19 @@ XXXXXXXXXX: Version 0.0.8-ALPHA exist (debian: Package iso-codes) - add all genres listed by id3 -L. Fix spellings. - lots of bug fixes, as usual + +2005-03-XX: Version 0.1.5-BETA +- add include files like stdio.h, needed in some environments +- fix genre import +- if you have mysql embedded 4.1.11 or better, you can access embedded + and external data bases with the same binary. If you omit the -h + parameter, embedded is used. Without embedded support compiled in, + the default for -h is still localhost +- renamed the Makefile conditional HAVE_SERVER to HAVE_ONLY_SERVER. This + better reflects the new functionality. +- if you want to connect to the local server using sockets, you now + do that with -h localhost. Up to now you had to specify -s. This is + no longer needed. This better reflects the mysql C API. As a con- + sequence, up to now not giving any argument to muggle called the + server on localhost using TCP, now it uses the faster sockets. You + can still request TCP by using -h 127.0.0.1 diff --git a/Makefile b/Makefile index 0b1c55c..1bc0296 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,10 @@ PLUGIN = muggle # HAVE_VORBISFILE=1 # HAVE_FLAC=1 -#if you want to use a dedicated Mysql server instead of the embedded code, +#if you do not want to compile in code for embedded sql, #define this in $VDRDIR/Make.config: -# HAVE_SERVER=1 -# +# HAVE_ONLY_SERVER=1 + ### The version number of this plugin (taken from the main source file): VERSION = $(shell grep 'static const char \*VERSION *=' $(PLUGIN).c | awk '{ print $$6 }' | sed -e 's/[";]//g') @@ -51,24 +51,24 @@ PACKAGE = vdr-$(ARCHIVE) ### Includes and Defines (add further entries here): INCLUDES += -I$(VDRDIR) -I$(VDRDIR)/include -I$(DVBDIR)/include \ - -I/usr/include/mysql/ -I/usr/include/taglib + $(shell mysql_config --cflags) $(shell taglib-config --cflags) -DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DMYSQLCLIENTVERSION='"$(shell mysql_config --version)"' ### The object files (add further files here): OBJS = $(PLUGIN).o i18n.o mg_valmap.o mg_mysql.o mg_sync.o mg_order.o mg_content.o mg_selection.o vdr_actions.o vdr_menu.o mg_tools.o \ - vdr_decoder_mp3.o vdr_decoder_ogg.o vdr_decoder_flac.o vdr_stream.o vdr_decoder.o vdr_player.o \ + vdr_decoder_mp3.o vdr_stream.o vdr_decoder.o vdr_player.o \ vdr_setup.o mg_setup.o -LIBS = -lmad -ltag -MILIBS = -ltag +LIBS = -lmad $(shell taglib-config --libs) +MILIBS = $(shell taglib-config --libs) -ifdef HAVE_SERVER -SQLLIBS = `mysql_config --libs` -DEFINES += -DHAVE_SERVER +ifdef HAVE_ONLY_SERVER +SQLLIBS = $(shell mysql_config --libs) +DEFINES += -DHAVE_ONLY_SERVER else -SQLLIBS = `mysql_config --libmysqld-libs` -L/lib +SQLLIBS = $(shell mysql_config --libmysqld-libs) -L/lib endif ifdef HAVE_VORBISFILE @@ -115,7 +115,7 @@ install: @cp mugglei /usr/local/bin/ # @install -m 755 mugglei /usr/local/bin/ -dist: clean +dist: clean mg_tables.h @-rm -rf $(TMPDIR)/$(ARCHIVE) @mkdir $(TMPDIR)/$(ARCHIVE) @cp -a * $(TMPDIR)/$(ARCHIVE) diff --git a/mg_mysql.c b/mg_mysql.c index 8c315f3..f50cafb 100644 --- a/mg_mysql.c +++ b/mg_mysql.c @@ -11,7 +11,9 @@ #include "mg_tools.h" #include +#include #include +#include #include #include #include @@ -20,6 +22,8 @@ bool needGenre2; static bool needGenre2_set; +bool NoHost(); +bool UsingEmbedded(); class mysqlhandle_t { public: @@ -27,22 +31,25 @@ class mysqlhandle_t { ~mysqlhandle_t(); }; -#ifndef HAVE_SERVER + static char *datadir; -static char *server_args[] = +static char *embedded_args[] = { "muggle", "--datadir=/tmp", // stupid default "--key_buffer_size=32M" }; -static char *server_groups[] = + +#ifndef HAVE_ONLY_SERVER +static char *embedded_groups[] = { "embedded", "server", "muggle_SERVER", 0 }; +#endif void set_datadir(char *dir) @@ -50,7 +57,7 @@ set_datadir(char *dir) mgDebug(1,"setting datadir to %s",dir); struct stat stbuf; datadir=strdup(dir); - asprintf(&server_args[1],"--datadir=%s",datadir); + asprintf(&embedded_args[1],"--datadir=%s",datadir); if (stat(datadir,&stbuf)) mkdir(datadir,0755); if (stat(datadir,&stbuf)) @@ -58,21 +65,33 @@ set_datadir(char *dir) mgError("Cannot access datadir %s: errno=%d",datadir,errno); } } -#endif + mysqlhandle_t::mysqlhandle_t() { -#ifndef HAVE_SERVER - mgDebug(1,"calling mysql_server_init"); - if (mysql_server_init(sizeof(server_args) / sizeof(char *), - server_args, server_groups)) +#ifndef HAVE_ONLY_SERVER + int argv_size; + if (UsingEmbedded()) + { + mgDebug(1,"calling mysql_server_init for embedded"); + argv_size = sizeof(embedded_args) / sizeof(char *); + } + else + { + if (strcmp(MYSQLCLIENTVERSION,"4.1.11")<0) + mgError("You have embedded mysql. For accessing external servers " + "you need mysql 4.1.11 but you have only %s", MYSQLCLIENTVERSION); + mgDebug(1,"calling mysql_server_init for external"); + argv_size = -1; + } + if (mysql_server_init(argv_size, embedded_args, embedded_groups)) mgDebug(3,"mysql_server_init failed"); #endif } mysqlhandle_t::~mysqlhandle_t() { -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER mgDebug(3,"calling mysql_server_end"); mysql_server_end(); #endif @@ -266,6 +285,12 @@ static char *db_cmds[] = "TYPE=MyISAM;" }; +bool +mgmySql::sql_query(const char *sql) +{ + return mysql_query(m_db,sql); +} + MYSQL_RES* mgmySql::exec_sql( string query) @@ -273,7 +298,7 @@ mgmySql::exec_sql( string query) if (!m_db || query.empty()) return 0; mgDebug(4,"exec_sql(%X,%s)",m_db,query.c_str()); - if (mysql_query (m_db, (query + ';').c_str ())) + if (sql_query (query.c_str ())) { mgError("SQL Error in %s: %s",query.c_str(),mysql_error (m_db)); std::cout<<"ERROR in " << query << ":" << mysql_error(m_db)< #include #include +#include #include #include #include @@ -208,7 +209,8 @@ mgSync::GetFileInfo(const char *filename) *slash='\''; *(slash+1)=0; } - const char *genrename=tag->genre().toCString(); + TagLib::String sgenre1=tag->genre(); + const char *genrename=sgenre1.toCString(); const char *genreid=m_Genres[genrename].c_str(); sql_Cstring(genreid,c_genre1); sql_Cstring(getlanguage(filename),c_lang); diff --git a/muggle.c b/muggle.c index 7259078..3137f78 100644 --- a/muggle.c +++ b/muggle.c @@ -49,15 +49,15 @@ mgMuggle::mgMuggle (void) { main = NULL; // defaults for database arguments - the_setup.DbHost = strdup ("localhost"); - the_setup.DbSocket = NULL; + the_setup.DbHost = 0; + the_setup.DbSocket = 0; the_setup.DbPort = 0; the_setup.DbName = strdup ("GiantDisc"); - the_setup.DbUser = strdup (""); - the_setup.DbPass = strdup (""); + the_setup.DbUser = 0; + the_setup.DbPass = 0; the_setup.GdCompatibility = false; the_setup.ToplevelDir = strdup ("/mnt/music/"); -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER char *buf; asprintf(&buf,"%s/.muggle",getenv("HOME")); set_datadir(buf); @@ -85,25 +85,40 @@ mgMuggle::CommandLineHelp (void) { // Return a string that describes all known command line options. return +#ifdef HAVE_ONLY_SERVER " -h HHHH, --host=HHHH specify database host (default is localhost)\n" - " -s SSSS --socket=PATH specify database socket (default is TCP connection)\n" +#else + " -h HHHH, --host=HHHH specify database host (default is mysql embedded)\n" +#endif + " -s SSSS --socket=PATH specify database socket\n" " -n NNNN, --name=NNNN specify database name (overridden by -g)\n" " -p PPPP, --port=PPPP specify port of database server (default is )\n" " -u UUUU, --user=UUUU specify database user (default is )\n" " -w WWWW, --password=WWWW specify database password (default is empty)\n" " -t TTTT, --toplevel=TTTT specify toplevel directory for music (default is /mnt/music)\n" -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER " -d DIRN, --datadir=DIRN specify directory for embedded sql data (default is $HOME/.muggle)\n" #endif " -g, --giantdisc enable full Giantdisc compatibility mode\n" - " -v, --verbose specify debug level. The higher the more. Default is 1\n"; + " -v, --verbose specify debug level. The higher the more. Default is 1\n" + "\n" + "if the specified host is localhost, sockets will be used if possible.\n" + "Otherwise the -s parameter will be ignored"; } bool mgMuggle::ProcessArgs (int argc, char *argv[]) { mgSetDebugLevel (1); - mgDebug (1, "mgMuggle::ProcessArgs"); + char b[1000]; + sprintf(b,"mgMuggle::ProcessArgs "); + for (int i=1;i1000) break;; + strcat(b," "); + strcat(b,argv[i]); + } + mgDebug(1,b); // Implement command line argument processing here if applicable. static struct option @@ -115,7 +130,7 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[]) {"port", required_argument, NULL, 'p'}, {"user", required_argument, NULL, 'u'}, {"password", required_argument, NULL, 'w'}, -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER {"datadir", required_argument, NULL, 'd'}, #endif {"toplevel", required_argument, NULL, 't'}, @@ -127,7 +142,7 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[]) c, option_index = 0; while ((c = -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER getopt_long (argc, argv, "gh:s:n:p:t:u:w:d:v:", long_options, #else getopt_long (argc, argv, "gh:s:n:p:t:u:w:v:", long_options, @@ -166,7 +181,7 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[]) the_setup.DbPass = strcpyrealloc (the_setup.DbPass, optarg); } break; -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER case 'd': { set_datadir(optarg); diff --git a/mugglei.c b/mugglei.c index 1e2f7ae..e5e7c21 100755 --- a/mugglei.c +++ b/mugglei.c @@ -71,7 +71,11 @@ int main( int argc, char *argv[] ) std::cout << "Only files ending in .flac, .mp3, .ogg (ignoring case) will be imported" << std::endl; std::cout << "" << std::endl; std::cout << "Options:" << std::endl; +#ifdef HAVE_ONLY_SERVER std::cout << " -h - specify host of mySql database server (default is 'localhost')" << std::endl; +#else + std::cout << " -h - specify host of mySql database server (default is mysql embedded')" << std::endl; +#endif std::cout << " -s - specify a socket for mySQL communication (default is TCP)" << std::endl; std::cout << " -n - specify database name (default is 'GiantDisc')" << std::endl; std::cout << " -u - specify user of mySql database (default is empty)" << std::endl; @@ -80,10 +84,13 @@ int main( int argc, char *argv[] ) std::cout << " -z - scan all database entries and delete entries for files not found" << std::endl; std::cout << " -z is not yet implemented" << std::endl; std::cout << " -c - delete the entire database and recreate a new empty one" << std::endl; -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER std::cout << " -d - the data directory for the embedded mysql server. Defaults to ./.muggle" << std::endl; #endif std::cout << " -v - the wanted log level, the higher the more. Default is 1" << std::endl; + std::cout << std::endl << std::endl; + std::cout << "if the specified host is localhost, sockets will be used if possible." << std::endl; + std::cout << "Otherwise the -s parameter will be ignored" << std::endl; exit( 1 ); } @@ -92,7 +99,7 @@ int main( int argc, char *argv[] ) import_assorted = false; delete_mode = false; create_mode = false; -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER char *buf; asprintf(&buf,"%s/.muggle",getenv("HOME")); set_datadir(buf); @@ -102,7 +109,7 @@ int main( int argc, char *argv[] ) // parse command line options while( 1 ) { -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER int c = getopt(argc, argv, "h:s:n:u:p:t:zcv:d:"); #else int c = getopt(argc, argv, "h:s:n:u:p:t:zcv:"); @@ -153,7 +160,7 @@ int main( int argc, char *argv[] ) { mgSetDebugLevel(atol(optarg)); } break; -#ifndef HAVE_SERVER +#ifndef HAVE_ONLY_SERVER case 'd': { set_datadir(optarg); diff --git a/vdr_actions.c b/vdr_actions.c index b389e38..4ab8483 100644 --- a/vdr_actions.c +++ b/vdr_actions.c @@ -29,6 +29,7 @@ #define DEBUG #include "mg_tools.h" #include "mg_order.h" +#include "mg_sync.h" static bool IsEntry(mgActions i) @@ -677,17 +678,39 @@ mgToggleSelection::Execute () osd()->newposition = selection ()->gotoPosition (); } -class mgSync : public mgCommand +class mgCmdSync : public mgOsdItem { public: + bool Enabled(mgActions on) { return true; } void Execute(); - const char *ButtonName() { return tr("Synchronize"); } + eOSState ProcessKey(eKeys key); + const char *ButtonName() { return tr("Synchronize database"); } }; + +static char *sync_args[] = +{ + ".", + 0 +}; + +eOSState +mgCmdSync::ProcessKey(eKeys key) +{ + if (key==kOk) + if (Interface->Confirm(tr("Synchronize database with track flles?"))) + { + Execute(); + return osContinue; + } + return osUnknown; +} + void -mgSync::Execute() +mgCmdSync::Execute() { - // selection()->Sync("."); + mgSync s; + s.Sync(sync_args); } //! \brief sets the default collection selection @@ -1228,7 +1251,7 @@ mgAction::Type() if (t == typeid(mgCreateOrder)) return actCreateOrder; if (t == typeid(mgDeleteOrder)) return actDeleteOrder; if (t == typeid(mgEditOrder)) return actEditOrder; - if (t == typeid(mgSync)) return actSync; + if (t == typeid(mgCmdSync)) return actSync; if (t == typeid(mgExternal0)) return actExternal0; if (t == typeid(mgExternal1)) return actExternal1; if (t == typeid(mgExternal2)) return actExternal2; @@ -1290,7 +1313,7 @@ actGenerate(const mgActions action) case actSetButton: result = new mgSetButton;break; case actShowList: result = new mgShowList;break; case actShowCommands: result = new mgShowCommands;break; - case actSync: result = new mgSync;break; + case actSync: result = new mgCmdSync;break; case actSetDefaultCollection: result = new mgSetDefaultCollection;break; case actOrder: result = new mgActOrder;break; case actUnused6: break; diff --git a/vdr_menu.c b/vdr_menu.c index 6472ad6..8e26afd 100644 --- a/vdr_menu.c +++ b/vdr_menu.c @@ -608,9 +608,6 @@ mgSubmenu::BuildOsd () AddAction(actClearCollection,on); AddAction(actChooseOrder,on); AddAction(actExportTracklist,on); -#if 0 - AddAction(actSync,on); -#endif cCommand *command; if (osd()->external_commands) { @@ -687,6 +684,20 @@ mgMenu::Process (eKeys key) return ExecuteButton(key); } +eOSState +mgTree::Process (eKeys key) +{ + eOSState result = osUnknown; + if (key!=kNone) + mgDebug(1,"mgTree::Process(%d)",key); + switch (key) + { + case k0:mgDebug(1,"ich bin k0");break; + default: result = mgMenu::Process(key); + } + return result; +} + void mgTree::BuildOsd () { diff --git a/vdr_menu.h b/vdr_menu.h index 227931c..ede022b 100644 --- a/vdr_menu.h +++ b/vdr_menu.h @@ -343,6 +343,7 @@ class mgTree:public mgMenu { public: mgTree(); + virtual eOSState Process (eKeys Key); protected: void BuildOsd (); }; diff --git a/vdr_setup.c b/vdr_setup.c index 95d7df2..c2f442e 100644 --- a/vdr_setup.c +++ b/vdr_setup.c @@ -20,6 +20,7 @@ #include #include "vdr_setup.h" +#include "vdr_actions.h" #include "i18n.h" @@ -55,6 +56,12 @@ mgMenuSetup::mgMenuSetup () Add (new cMenuEditIntItem (tr ("Setup.Muggle$Limiter level"), &m_data.LimiterLevel, MIN_LIMITER_LEVEL, 100)); + + mgAction *a = actGenerate(actSync); + const char *mn = a->MenuName(); + a->SetText(mn); + free(const_cast(mn)); + Add(dynamic_cast(a)); } -- cgit v1.2.3