Esempio n. 1
0
static void
totem_edit_chapter_init (TotemEditChapter *self)
{
	GtkBuilder	*builder;

	self->priv = TOTEM_EDIT_CHAPTER_GET_PRIVATE (self);
	builder = load_interface ("chapters", "chapters-edit.ui", FALSE, NULL, self);

	if (builder == NULL) {
		self->priv->container = NULL;
		return;
	}

	self->priv->container = GTK_WIDGET (gtk_builder_get_object (builder, "main_vbox"));
	g_object_ref (self->priv->container);
	self->priv->title_entry = GTK_ENTRY (gtk_builder_get_object (builder, "title_entry"));

	g_object_unref (builder);
}
Esempio n. 2
0
int main(int argc, char **argv)
{
    const char *device_param = default_pcm_device;
    char *prefsdir;
    char thefile[1024];
    char str[1024];
    float start_vol = 1.0;
    int ap_result = 0;
    int use_fragsize = -1; // Initialized
    int use_fragcount = -1; // later
    int do_loopsong = 0;
    int do_looplist = 0;
    int do_enqueue = 0;
    int do_replace = 0;
    int do_realtime = 0;
    int do_remote_control = 0;
    int do_shuffle = 0;
    int do_start = 0;
    int do_stop = 0;
    int do_prev = 0;
    int do_next = 0;
    int do_pause = 0;
    int do_jump = -1;
    int do_clear = 0;
    int do_seek = -1;
    int do_relative = 0;
    int do_setvol = 0;
    int do_quit = 0;
    int do_status = 0;
    int do_speed = 0;
    float speed_val = 0.0;
    int do_onebyone = 0;

    int use_freq = OUTPUT_RATE;
    float use_vol = 1.0;
    int use_session = 0;
    int do_crossfade = 0;
    int do_save = 1;
    int bool_val = 0;
    const char *use_output = NULL;
    char *use_interface = NULL;
    char *use_config = NULL;
    char *use_loopsong = NULL;
    char *use_onebyone = NULL;
    char *use_looplist = NULL;

    int opt;
    int option_index;
    const char *options = "Cc:d:eEf:F:g:hi:J:I:l:n:NMp:qrs:vRSQVxo:";
    struct option long_options[] = {
        /*	{ "long_option", take_argument, 0, 'short_option' }, */
        { "config", 1, 0, 'c' },
        { "device", 1, 0, 'd' },
        { "enqueue", 0, 0, 'e' },
        { "replace", 0, 0, 'E' },
        { "fragsize", 1, 0, 'f' },
        { "frequency", 1, 0, 'F' },
        { "fragcount", 1, 0, 'g' },
        { "help", 0, 0, 'h' },
        { "interface", 1, 0, 'i' },
        { "volume", 1, 0, 'Y' },
        { "session", 1, 0, 'n' },
        { "nosave", 0, 0, 'N' },
        { "path", 1, 0, 'p' },
        { "quiet", 0, 0, 'q' },
        { "realtime", 0, 0, 'r' },
        { "script", 1, 0, 'I'},
        { "session-name", 1, 0, 's' },
        { "version", 0, 0, 'v' },
        { "verbose", 0, 0, 'V' },
        { "reverb", 0, 0, 'R' },
        { "loopsong", 1, 0, 'L' },
        { "looplist", 1, 0, 'P' },
        { "crossfade", 0, 0, 'x' },
        { "output", 1, 0, 'o' },
        { "stop", 0, 0, 'U' },
        { "pause", 0, 0, 'O' },
        { "start", 0, 0, 'T' },
        { "shuffle", 0, 0, 'S' },
        { "prev", 0, 0, 'Q' },
        { "next", 0, 0, 'M' },
        { "jump", 1, 0, 'J' },
        { "seek", 1, 0, 'X' },
        { "relative", 1, 0, 'Z' },
        { "speed", 1, 0, 'H' },
        { "clear", 0, 0, 'C' },
        { "startvolume", 1, 0, 'l' },
        { "quit", 0, 0, 'A' },
        { "status", 0, 0, 'B' },
        { "onebyone", 1, 0, 't' },

        // Options that we want to be able to pass on to gtk_init(). See man
        // gtk-options(7).
        // Give all of these an option number of 128 because we're going to
        // ignore them option switch statement anyway.
        { "gtk-module", 1, 0, 128 },
        { "gtk-debug", 1, 0, 128 },
        { "gtk-no-debug", 1, 0, 128 },
        { "g-fatal-warnings", 0, 0, 128 },

        { "display", 1, 0, 128 },
        { "screen", 1, 0, 128 },
        { "sync", 0, 0, 128 },
        { "no-xshm", 0, 0, 128 },
        { "name", 1, 0, 128 },
        { "class", 1, 0, 128 },
        { "gxid_host", 1, 0, 128 },
        { "gxid_port", 1, 0, 128 },
        { "xim-preedit", 0, 0, 128 },
        { "xim-status", 0, 0, 128 },
        { "gdk-debug", 1, 0, 128 },
        { "gdk-no-debug", 1, 0, 128 },

        // End of list marker.
        { 0, 0, 0, 0 }
    };


    // First setup signal handler
    signal(SIGPIPE, nonfatal_sighandler);   // PIPE (socket control)
    signal(SIGTERM, exit_sighandler);	// kill
    signal(SIGHUP, exit_sighandler);	// kill -HUP / xterm closed
    signal(SIGINT, exit_sighandler);	// Interrupt from keyboard
    signal(SIGQUIT, exit_sighandler);	// Quit from keyboard
    // fatal errors
    signal(SIGBUS, exit_sighandler);	// bus error
    //signal(SIGSEGV, exit_sighandler);	// segfault
    signal(SIGILL, exit_sighandler);	// illegal instruction
    signal(SIGFPE, exit_sighandler);	// floating point exc.
    signal(SIGABRT, exit_sighandler);	// abort()

    // Enable locale support
#ifdef ENABLE_NLS
    setlocale (LC_ALL, "");
    bindtextdomain(PACKAGE, LOCALEDIR);
    textdomain(PACKAGE);
    bind_textdomain_codeset (PACKAGE, "UTF-8");
#endif

    // Init global mutexes
    pthread_mutex_init(&playlist_sort_seq_mutex, NULL);
#if !defined(EMBEDDED)
    init_effects();
#endif
    while ((opt = getopt_long(argc, argv, options, long_options, &option_index)) != EOF) {
        switch(opt) {
        case 'A':
            do_remote_control = 1;
            do_quit = 1;
            break;
        case 'B':
            do_remote_control = 1;
            do_status = 1;
            break;
        case 'c':
            if (strlen(optarg) < 1023) {
                use_config = optarg;
            } else {
                alsaplayer_error("config file path too long");
                return 1;
            }
            break;
        case 'd':
            device_param = optarg;
            break;
        case 'E':
            do_replace = 1;
        case 'e':
            do_enqueue = 1;
            break;
        case 'f':
            use_fragsize = atoi(optarg);
            if (!use_fragsize) {
                alsaplayer_error("invalid fragment size");
                return 1;
            }
            if (use_fragsize > 32768) {
                alsaplayer_error("fragment size (%d) out of range (0-32768)", use_fragsize);
                return 1;
            }
            break;
        case 'F':
            use_freq = atoi(optarg);
            if (use_freq < 8000 || use_freq > 48000) {
                alsaplayer_error("frequency (%d) out of range (8000-48000)", use_freq);
                return 1;
            }
            break;
        case 'g':
            use_fragcount = atoi(optarg);
            if (use_fragcount < 2 || use_fragcount > 128) {
                alsaplayer_error("fragcount (%d) out of range (2-128)", use_fragcount);
                return 1;
            }
            break;
        case 'h':
            help();
            return 0;
        case 'H':
            if ((sscanf(optarg, "%f", &speed_val))) {
                do_remote_control = 1;
                do_speed = 1;
            }
            break;
        case 'i':
            use_interface = optarg;
            break;
        case 'l':
            start_vol = atof(optarg);
            if (start_vol < 0.0 || start_vol > 1.0) {
                alsaplayer_error("volume (%.3f) out of range: using 1.0", start_vol);
                start_vol = 1.0;
            }
            break;
        case 'L':
            do_remote_control = 1;
            do_loopsong = 1;
            use_loopsong = optarg;
            break;
        case 'Y':
            do_remote_control = 1;
            do_setvol = 1;
            use_vol = atof(optarg);
            if (use_vol < 0.0 || use_vol > 1.0) {
                alsaplayer_error("volume (%.3f) out of range: using 1.0", use_vol);
                use_vol = 1.0;
            }
            break;
        case 'n':
            use_session = atoi(optarg);
            break;
        case 'N':
            do_save = 0;
            break;
        case 'O':
            do_remote_control = 1;
            do_pause = 1;
            break;
        case 'p':
            global_pluginroot = optarg;
            break;
        case 'q':
            global_quiet = 1;
            break;
        case 'r':
            do_realtime = 1;
            break;
        case 's':
            if (strlen(optarg) < 32) {
                global_session_name = strdup(optarg);
            } else {
                alsaplayer_error("max 32 char session name, ignoring");
            }
            break;
        case 'v':
            version();
            return 0;
        case 'V':
            global_verbose = 1;
            break;
        case 'R':
            break;
        case 'P':
            do_remote_control = 1;
            do_looplist = 1;
            use_looplist = optarg;
            break;
        case 'x':
            do_crossfade = 1;
            break;
        case 'o':
            use_output = optarg;
            break;
        case '?':
            return 1;
        case 'I':
            global_interface_script = optarg;
            break;
        case 'U':
            do_remote_control = 1;
            do_stop = 1;
            break;
        case 'T':
            do_remote_control = 1;
            do_start = 1;
            break;
        case 'S':
            do_remote_control = 1;
            do_shuffle = 1;
            break;
        case 'Q':
            do_remote_control = 1;
            do_prev = 1;
            break;
        case 'M':
            do_remote_control = 1;
            do_next = 1;
            break;
        case 'J':
            do_remote_control = 1;
            do_jump = atoi(optarg);
            break;
        case 'C':
            do_remote_control = 1;
            do_clear = 1;
            break;
        case 'X':
            do_remote_control = 1;
            do_seek = atoi(optarg);
            break;
        case 'Z':
            do_remote_control = 1;
            do_relative = 1;
            do_seek = atoi(optarg);
            break;
        case 't':
            do_remote_control = 1;
            do_onebyone = 1;
            use_onebyone = optarg;
            break;
        case 128:
            // Gtk-option which we ignore.
            break;
        default:
            alsaplayer_error("Unknown option '%c'", opt);
            break;
        }
    }

    prefsdir = get_prefsdir();

    mkdir(prefsdir, 0700);	/* XXX We don't do any error checking here */
    snprintf(thefile, sizeof(thefile)-21, "%s/config", prefsdir);
    if (use_config)
        ap_prefs = prefs_load(use_config);
    else
        ap_prefs = prefs_load(thefile);
    if (!ap_prefs) {
        alsaplayer_error("Invalid config file %s\n", use_config ? use_config : thefile);
        return 1;
    }
    /* Initialize some settings (and populate the prefs system if needed */

    if (use_fragsize < 0)
        use_fragsize = prefs_get_int(ap_prefs, "main", "period_size", 4096);
    if (use_fragcount < 0)
        use_fragcount = prefs_get_int(ap_prefs, "main", "period_count", 8);


    if (global_verbose)
        puts(copyright_string);

    if (!global_pluginroot) {
        global_pluginroot = strdup (ADDON_DIR);
    }


    if (use_session == 0) {
        for (; use_session < MAX_REMOTE_SESSIONS+1; use_session++) {
            ap_result = ap_session_running(use_session);

            if (ap_result)
                break;
        }
        if (use_session == (MAX_REMOTE_SESSIONS+1)) {
            //alsaplayer_error("No remote session found");
            if (do_remote_control) {
                alsaplayer_error("No active sessions");
                return 1;
            }
            do_enqueue = 0;
        } else {
            //alsaplayer_error("Found session %d", use_session);
            if (prefs_get_bool(ap_prefs, "main", "multiopen", 1) == 0) {
                // We should not spawn another alsaplayer
                //alsaplayer_error("Using session %d, not doing multiopen", use_session);
                do_enqueue = 1;
                do_replace = 1;
            }
        }
    }

    // Check if we're in remote control mode
    if (do_remote_control) {
        if (do_quit) {
            ap_quit(use_session);
            return 0;
        } else if (do_status) {
            char res[1024];
            float fres;
            int ires;
            fprintf(stdout, "---------------- Session ----------------\n");
            if (ap_get_session_name(use_session, res) && strlen(res))
                fprintf(stdout, "name: %s\n", res);
            if (ap_get_playlist_length(use_session, &ires))
                fprintf(stdout, "playlist_length: %d\n", ires);
            if (ap_get_volume(use_session, &fres))
                fprintf(stdout, "volume: %.2f\n", fres);
            if (ap_get_speed(use_session, &fres))
                fprintf(stdout, "speed: %d%%\n", (int)(fres * 100));
            fprintf(stdout, "-------------- Current Track ------------\n");
            if (ap_get_artist(use_session, res) && strlen(res))
                fprintf(stdout, "artist: %s\n", res);
            if (ap_get_title(use_session, res) && strlen(res))
                fprintf(stdout, "title: %s\n", res);
            if (ap_get_album(use_session, res) && strlen(res))
                fprintf(stdout, "album: %s\n", res);
            if (ap_get_genre(use_session, res) && strlen(res))
                fprintf(stdout, "genre: %s\n", res);
            if (ap_get_file_path(use_session, res) && strlen(res))
                fprintf(stdout, "path: %s\n", res);
            if (ap_get_blocks(use_session, &ires))
                fprintf(stdout, "blocks: %d\n", ires);
            if (ap_get_length(use_session, &ires))
                fprintf(stdout, "length: %d second%s\n", ires, (ires == 1) ? "": "s");
            if (ap_get_position(use_session, &ires))
                fprintf(stdout, "position: %d\n", ires);
            fprintf(stdout, "-----------------------------------------\n");
            return 0;
        } else if (do_setvol) {
            ap_set_volume(use_session, use_vol);
            return 0;
        } else if (do_shuffle) {
            ap_shuffle_playlist(use_session);
            return 0;
        } else if (do_start) {
            ap_play(use_session);
            return 0;
        } else if (do_stop) {
            ap_stop(use_session);
            return 0;
        } else if (do_pause) {
            if (ap_is_paused(use_session, &bool_val)) {
                if (bool_val)
                    ap_unpause(use_session);
                else
                    ap_pause(use_session);
            }
            return 0;
        } else if (do_next) {
            ap_next(use_session);
            return 0;
        } else if (do_prev) {
            ap_prev(use_session);
            return 0;
        } else if (do_jump >= 0) {
            ap_jump_to(use_session, do_jump);
            return 0;
        } else if (do_clear) {
            ap_clear_playlist(use_session);
            return 0;
        } else if (do_relative) {
            if (do_seek != 0)
                ap_set_position_relative(use_session, do_seek);
            return 0;
        } else if (do_speed) {
            if (speed_val < -10.0 || speed_val > 10.0) {
                alsaplayer_error("Speed out of range, must be between -10.00 and 10.00");
                return 1;
            }
            ap_set_speed(use_session, speed_val);
            return 0;
        } else if (do_seek >= 0) {
            ap_set_position(use_session, do_seek);
            return 0;
        } else if (do_loopsong) {
            if (strcasecmp(use_loopsong, "on") != 0) {
                do_loopsong = false;
            }
            ap_set_looping(use_session, do_loopsong);
            return 0;
        } else if (do_onebyone) {
            if (strcasecmp(use_onebyone, "on") != 0) {
                do_onebyone = false;
            }
            ap_set_onebyone(use_session, do_onebyone);
            return 0;
        } else if (do_looplist) {
            if (strcasecmp(use_looplist, "on") != 0) {
                do_looplist = false;
            }
            ap_set_playlist_looping(use_session, do_looplist);
            return 0;
        } else
            alsaplayer_error("No remote control command executed.");
    }


    // Check if we need to enqueue the files
    if (do_enqueue) {
        char queue_name[2048];
        int count = 0;
        int was_playing = 0;
        int playlist_length = 0;

        count = optind;
        ap_result = 1;

        if (do_replace && count < argc) {
            ap_is_playing(use_session, &was_playing);
            if (was_playing) {
                ap_stop(use_session);
            }
            ap_clear_playlist(use_session);
        } else {
            ap_get_playlist_length(use_session, &playlist_length);
            if (!playlist_length) { // Empty list so fire up after add
                was_playing = 1;
            }
        }
        while (count < argc && ap_result) {
            if (is_playlist(argv[count])) {
                ap_add_playlist(use_session, argv[count]);
                count++;
                continue;
            }
            if (argv[count][0] != '/' &&
                    strncmp(argv[count], "http://", 7) != 0 &&
                    strncmp(argv[count], "ftp://", 6) != 0) {
                // Not absolute so append cwd
                if (getcwd(queue_name, 1024) == NULL) {
                    alsaplayer_error("error getting cwd");
                    return 1;
                }
                ap_strlcat(queue_name, "/", sizeof(queue_name));
                ap_strlcat(queue_name, argv[count], sizeof(queue_name));
            } else
                ap_strlcpy(queue_name, argv[count], sizeof(queue_name));
            count++;
            //alsaplayer_error("Adding %s", queue_name);
            ap_result = ap_add_path(use_session, queue_name);
            //alsaplayer_error("ap_result = %d", ap_result);
        }
        if (was_playing)
            ap_jump_to(use_session, 1);
        if (ap_result)
            return 0;
    }

    AlsaNode *node;

    // Check if we want jack
    if (strcmp(argv[0], "jackplayer") == 0) {
        use_output = "jack";
    }

    // Check the output option
    if (use_output == NULL) {
        use_output = prefs_get_string(ap_prefs, "main",
                                      "default_output", "alsa");
    }

    // Else do the usual plugin based thing
    node = new AlsaNode(use_output, device_param, do_realtime);

    if (!node->RegisterPlugin(use_output)) {
        alsaplayer_error("Failed to load output plugin \"%s\". Trying defaults.", use_output);
        if (!node->RegisterPlugin())
            return 1;
    }
    int output_is_ok = 0;
    int output_alternate = 0;

    do {
        if (!node || !node->ReadyToRun()) {
            alsaplayer_error
            ("failed to load output plugin (%s). exitting...",
             use_output ? use_output: "alsa,etc.");
            return 1;
        }
        if (!node->SetSamplingRate(use_freq) ||
                !node->SetStreamBuffers(use_fragsize, use_fragcount, 2)) {
            alsaplayer_error
            ("failed to configure output device...trying OSS");
            /* Special case for OSS, since it's easiest to get going, so try it */
            if (!output_alternate) {
                output_alternate = 1;
                node->RegisterPlugin("oss");
                continue;
            } else {
                return 1;
            }
        }
        output_is_ok = 1;	/* output device initialized */
    } while (!output_is_ok);

    // Initialise reader
    reader_init ();

    // Initialise playlist - must be done before things try to register with it
    playlist = new Playlist(node);

    if (!prefs_get_bool(ap_prefs, "main", "play_on_start", false))
        playlist->Pause();
    else
        playlist->UnPause();

    if (!playlist) {
        alsaplayer_error("Failed to create Playlist object");
        return 1;
    }
    // Add any command line arguments to the playlist
    if (optind < argc) {
        std::vector < std::string > newitems;
        while (optind < argc) {
            if (is_playlist(argv[optind])) {
                if (global_verbose)
                    alsaplayer_error("Loading playlist (%s)", argv[optind]);
                playlist->Load(std::string(argv[optind++]),
                               playlist->Length(), false);
            } else {
                newitems.push_back(std::string(argv[optind++]));
            }
        }
        playlist->Insert(newitems, playlist->Length());
    } else {
        prefsdir = get_prefsdir();
        snprintf(thefile, sizeof(thefile)-28, "%s/alsaplayer.m3u", prefsdir);
        playlist->Load(thefile, playlist->Length(), false);
    }

    // Loop song
    if (do_loopsong) {
        playlist->LoopSong();
    }
    // Loop Playlist
    if (do_looplist) {
        playlist->LoopPlaylist();
    }
    // Play songs one by one
    if (do_onebyone) {
        playlist->SetOneByOne();
    }
    // Cross fading
    if (do_crossfade) {
        playlist->Crossfade();
    }
    // Set start volume
    playlist->GetCorePlayer()->SetVolume(start_vol);


    interface_plugin_info_type interface_plugin_info;
    interface_plugin *ui;

    if (get_interface_from_argv0 (argv[0], str))
        use_interface = str;

    if (use_interface && *use_interface) {
        if (!(interface_plugin_info = load_interface(use_interface))) {
            alsaplayer_error("Failed to load interface %s\n", use_interface);
            goto _fatal_err;
        }
    } else {
        const char *interface = prefs_get_string
                                (ap_prefs, "main", "default_interface", "gtk2");
        // if we're trying to use the old gtk-1 interface, use gtk-2 instead
        if (strcmp (interface, "gtk") == 0)
            interface = "gtk2";
        // if we're trying to use the gtk interface, but we have no
        // $DISPLAY, use the text interface instead
        if (strcmp (interface, "gtk2") == 0 && !getenv("DISPLAY"))
            interface = "text";
        if (!(interface_plugin_info = load_interface(interface))) {
            if (!(interface_plugin_info = load_interface(prefs_get_string
                                          (ap_prefs, "main", "fallback_interface", "text")))) {
                alsaplayer_error("Failed to load text interface. This is bad (%s,%s,%s)",
                                 interface, interface,
                                 global_pluginroot);
                goto _fatal_err;
            }
        }
    }
    if (interface_plugin_info) {
        ui = interface_plugin_info();

        if (global_verbose)
            printf("Interface plugin: %s\n", ui->name);
        if (!ui->init()) {
            alsaplayer_error("Failed to load interface plugin. Should fall back to text\n");
        } else {
            control_socket_start(playlist, ui);
            ui->start(playlist, argc, argv);
            ui->close();
            // Unfortunately gtk+ is a pig when it comes to
            // cleaning up its resources; it doesn't!
            // so we can never safely dlclose gtk+ based
            // user interfaces, bah!
            //dlclose(ui->handle);
            control_socket_stop();
        }
    }
    // Save playlist before exit
    prefsdir = get_prefsdir();
    snprintf(thefile, sizeof(thefile)-25, "%s/alsaplayer", prefsdir);
    playlist->Save(thefile, PL_FORMAT_M3U);

    // Save preferences
    if (ap_prefs && do_save) {
        if (prefs_save(ap_prefs) < 0) {
            alsaplayer_error("failed to save preferences.");
        }
    }

_fatal_err:
    delete playlist;
    //delete p;
    delete node;
    if (global_session_name)
        free(global_session_name);

    return 0;
}
	bool CModuleManager::load_module( const string &filename, CInterfaceDefinition::module_source source, GUID &module_guid )
	{
		unzFile unzip_file;

		module_guid = CGuidHelper::null_guid;

		unzip_file = unzOpen( filename.c_str() );
		if( !unzip_file )
		{
			INTEGRA_TRACE_ERROR << "Unable to open zip: " << filename;
			return false;
		}

		CInterfaceDefinition *interface_definition = load_interface( unzip_file );
		if( !interface_definition ) 
		{
			INTEGRA_TRACE_ERROR << "Failed to load interface: " << filename;
			unzClose( unzip_file );
			return false;
		}

		module_guid = interface_definition->get_module_guid();

		if( m_module_id_map.count( module_guid ) > 0 )
		{
			INTEGRA_TRACE_VERBOSE << "Module already loaded: " << interface_definition->get_interface_info().get_name();
			delete interface_definition;
			unzClose( unzip_file );
			return false;
		}

		const CInterfaceInfo &interface_info = CInterfaceInfo::downcast( interface_definition->get_interface_info() );
		if( interface_info.get_implemented_in_libintegra() && source != CInterfaceDefinition::MODULE_SHIPPED_WITH_INTEGRA )
		{
			INTEGRA_TRACE_ERROR << "Attempt to load 'implemented in libintegra' module as 3rd party or embedded: " << interface_definition->get_interface_info().get_name();
			delete interface_definition;
			unzClose( unzip_file );
			return false;
		}

		interface_definition->set_file_path( filename );
		interface_definition->set_module_source( source );

		m_module_id_map[ interface_definition->get_module_guid() ] = interface_definition;

		if( m_origin_id_map.count( interface_definition->get_origin_guid() ) > 0 )
		{
			INTEGRA_TRACE_VERBOSE << "Two modules with same origin!  Leaving original in origin->interface table: " << interface_definition->get_interface_info().get_name();
		}
		else
		{
			m_origin_id_map[ interface_definition->get_origin_guid() ] = interface_definition;
		}

		if( interface_definition->is_core_interface() )
		{
			const string &name = interface_definition->get_interface_info().get_name();
			if( m_core_name_map.count( name ) > 0 )
			{
				INTEGRA_TRACE_VERBOSE << "Two core modules with same name!  Leaving original in name->interface table: " << name;
			}
			else
			{
				m_core_name_map[ name ] = interface_definition;
			}
		}
	
		m_module_ids.insert( interface_definition->get_module_guid() );

		if( interface_definition->has_implementation() )
		{
			unsigned int checksum = 0;
			extract_implementation( unzip_file, *interface_definition, checksum );

			interface_definition->set_implementation_checksum( checksum );
		}

		unzClose( unzip_file );

		return true;
	}
Esempio n. 4
0
int
main(int argc, char *argv[]) {
    cam cam_object, *cam;
    Display *display;
    Screen *screen_num;
    gchar *poopoo = NULL;
    gchar *pixfilename = "camorama/camorama.png";
    gchar *filename;            //= "/usr/opt/garnome/share/camorama/camorama.glade";
    int x = -1, y = -1;
    gboolean buggery = FALSE;
    GtkWidget *button;
    GConfClient *gc;

    const struct poptOption popt_options[] = {
        {"version", 'V', POPT_ARG_NONE, &ver, 0,
         N_("show version and exit"), NULL},
        {"device", 'd', POPT_ARG_STRING, &poopoo, 0,
         N_("v4l device to use"), NULL},
        {"debug", 'D', POPT_ARG_NONE, &buggery, 0,
         N_("enable debugging code"), NULL},
        {"width", 'x', POPT_ARG_INT, &x, 0, N_("capture width"),
         NULL},
        {"height", 'y', POPT_ARG_INT, &y, 0, N_("capture height"),
         NULL},
        {"max", 'M', POPT_ARG_NONE, &max, 0,
         N_("maximum capture size"), NULL},
        {"min", 'm', POPT_ARG_NONE, &min, 0,
         N_("minimum capture size"), NULL},
        {"half", 'H', POPT_ARG_NONE, &half, 0,
         N_("middle capture size"), NULL},
        {"read", 'R', POPT_ARG_NONE, &use_read, 0,
         N_("use read() rather than mmap()"), NULL},
        POPT_TABLEEND
    };

    cam = &cam_object;
    /* set some default values */
    cam->frame_number = 0;
    cam->pic = NULL;
    cam->pixmap = NULL;
    cam->size = PICHALF;
    cam->video_dev = NULL;
    cam->read = FALSE;

    bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
    setlocale (LC_ALL, "");

    /* gnome_program_init  - initialize everything (gconf, threads, etc) */
    gnome_program_init (PACKAGE_NAME, PACKAGE_VERSION, LIBGNOMEUI_MODULE, argc, argv,
                        GNOME_PARAM_APP_DATADIR, PACKAGE_DATA_DIR,
                        GNOME_PARAM_POPT_TABLE, popt_options,
                        GNOME_PARAM_HUMAN_READABLE_NAME, _("camorama"), NULL);

    /* gtk is initialized now */
    camorama_stock_init();
    camorama_filters_init();

    cam->debug = buggery;

	cam->x = x;
	cam->y = y;
	glade_gnome_init ();
	glade_set_custom_handler (camorama_glade_handler,
				  cam);


    if (ver) {
        fprintf (stderr, _("\n\nCamorama version %s\n\n"), VERSION);
        exit (0);
    }
    if (max) {
        cam->size = PICMAX;
    }
    if (min) {
        cam->size = PICMIN;
    }
    if (half) {
        cam->size = PICHALF;
    }
    if (use_read) {
        printf ("gah!\n");
        cam->read = TRUE;
    }
    gc = gconf_client_get_default ();
    cam->gc = gc;

    gconf_client_add_dir (cam->gc, PATH, GCONF_CLIENT_PRELOAD_NONE, NULL);
    gconf_client_notify_add (cam->gc, KEY1, (void *) gconf_notify_func,
                             cam->pixdir, NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY5, (void *) gconf_notify_func,
                             cam->rhost, NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY2, (void *) gconf_notify_func,
                             cam->capturefile, NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY3,
                             (void *) gconf_notify_func_int,
                             GINT_TO_POINTER (cam->savetype), NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY4,
                             (void *) gconf_notify_func_bool,
                             &cam->timestamp, NULL, NULL);

    if (!poopoo) {
	gchar const* gconf_device = gconf_client_get_string(cam->gc, KEY_DEVICE, NULL);
	if(gconf_device) {
		cam->video_dev = g_strdup(gconf_device);
	} else {
		cam->video_dev = g_strdup ("/dev/video0");
	}
    } else {
        cam->video_dev = g_strdup (poopoo);
    }

    cam->pixdir = g_strdup (gconf_client_get_string (cam->gc, KEY1, NULL));
    cam->capturefile =
        g_strdup (gconf_client_get_string (cam->gc, KEY2, NULL));
    cam->rhost = g_strdup (gconf_client_get_string (cam->gc, KEY5, NULL));
    cam->rlogin = g_strdup (gconf_client_get_string (cam->gc, KEY6, NULL));
    cam->rpw = g_strdup (gconf_client_get_string (cam->gc, KEY7, NULL));
    cam->rpixdir = g_strdup (gconf_client_get_string (cam->gc, KEY8, NULL));
    cam->rcapturefile =
        g_strdup (gconf_client_get_string (cam->gc, KEY9, NULL));
    cam->savetype = gconf_client_get_int (cam->gc, KEY3, NULL);
    cam->rsavetype = gconf_client_get_int (cam->gc, KEY10, NULL);
    cam->ts_string =
        g_strdup (gconf_client_get_string (cam->gc, KEY16, NULL));
    cam->date_format = "%Y-%m-%d %H:%M:%S";
    cam->timestamp = gconf_client_get_bool (cam->gc, KEY4, NULL);
    cam->rtimestamp = gconf_client_get_bool (cam->gc, KEY11, NULL);

    cam->cap = gconf_client_get_bool (cam->gc, KEY12, NULL);
    cam->rcap = gconf_client_get_bool (cam->gc, KEY13, NULL);
    cam->timefn = gconf_client_get_bool (cam->gc, KEY14, NULL);
    cam->rtimefn = gconf_client_get_bool (cam->gc, KEY15, NULL);
    cam->usestring = gconf_client_get_bool (cam->gc, KEY18, NULL);
    cam->usedate = gconf_client_get_bool (cam->gc, KEY19, NULL);
    cam->acap = gconf_client_get_bool (cam->gc, KEY20, NULL);
    cam->timeout_interval = gconf_client_get_int (cam->gc, KEY21, NULL);
    cam->show_adjustments = gconf_client_get_bool (cam->gc, KEY22, NULL);
	 cam->show_effects = gconf_client_get_bool (cam->gc, KEY23, NULL);


    /* get desktop depth */
    display = (Display *) gdk_x11_get_default_xdisplay ();
    screen_num = xlib_rgb_get_screen ();
    gdk_pixbuf_xlib_init (display, 0);
    cam->desk_depth = xlib_rgb_get_depth ();

    cam->dev = open (cam->video_dev, O_RDWR);

    camera_cap (cam);
    get_win_info (cam);

    /* query/set window attributes */
    cam->vid_win.x = 0;
    cam->vid_win.y = 0;
    cam->vid_win.width = cam->x;
    cam->vid_win.height = cam->y;
    cam->vid_win.chromakey = 0;
    cam->vid_win.flags = 0;

    set_win_info (cam);
    get_win_info (cam);

    /* get picture attributes */
    get_pic_info (cam);
//	set_pic_info(cam);
    /* set_pic_info(cam); */
    cam->contrast = cam->vid_pic.contrast;
    cam->brightness = cam->vid_pic.brightness;
    cam->colour = cam->vid_pic.colour;
    cam->hue = cam->vid_pic.hue;
    cam->wb = cam->vid_pic.whiteness;
    cam->depth = cam->vid_pic.depth / 8;
    cam->pic_buf = malloc (cam->x * cam->y * cam->depth);
    cam->tmp =
        malloc (cam->vid_cap.maxwidth * cam->vid_cap.maxheight * cam->depth);
    //cam->tmp = NULL;
    /* set the buffer size */
    if (cam->read == FALSE) {
        set_buffer (cam);
    }
    //cam->read = FALSE;
    /* initialize cam and create the window */

    if (cam->read == FALSE) {
        pt2Function = timeout_func;
        init_cam (NULL, cam);
    } else {
        printf ("using read()\n");
        cam->pic =
            realloc (cam->pic,
                     (cam->vid_cap.maxwidth * cam->vid_cap.maxheight * 3));
        pt2Function = read_timeout_func;
    }
    cam->pixmap = gdk_pixmap_new (NULL, cam->x, cam->y, cam->desk_depth);

    filename =
        gnome_program_locate_file (NULL,
                                   GNOME_FILE_DOMAIN_APP_DATADIR,
                                   "camorama/camorama.glade", TRUE, NULL);
    if (filename == NULL) {
        error_dialog (_
                      ("Couldn't find the main interface file (camorama.glade)."));
        exit (1);
    }

    //pixfilename = gnome_program_locate_file(NULL, GNOME_FILE_DOMAIN_APP_DATADIR, "pixmaps/camorama.png", TRUE, NULL);
    //printf("pixfile = %s\n",pixfilename);
    //pixfilename);
    //printf("pixfile = %s\n",pixfilename);
    cam->xml = glade_xml_new (filename, NULL, NULL);
    /*eggtray */

    /*tray_icon = egg_tray_icon_new ("Our other cool tray icon");
     * button = gtk_button_new_with_label ("This is a another\ncool tray icon");
     * g_signal_connect (button, "clicked",
     * G_CALLBACK (second_button_pressed), tray_icon);
     * 
     * gtk_container_add (GTK_CONTAINER (tray_icon), button);
     * gtk_widget_show_all (GTK_WIDGET (tray_icon)); */
    load_interface (cam);

    cam->idle_id = gtk_idle_add ((GSourceFunc) pt2Function, (gpointer) cam);

    gtk_timeout_add (2000, (GSourceFunc) fps, cam->status);
    gtk_main ();
    return 0;
}