Exemple #1
0
/** \brief Create and initialise module manger.
 *  \return The main module container widget (GtkNotebook).
 *
 * This function creates and initialises the module manager widget, which
 * consist of a GtkNotebook container. Before returning the container to the
 * caller, the function checks whether any modules should be restored (ie.
 * openend), if yes, it creates them and adds them to the notebook.
 *
 */
GtkWidget *
mod_mgr_create (void)
{
    gchar  *openmods = NULL;
    gchar **mods;
    gint    count,i;
    GtkWidget *module;
    gchar     *modfile;
    gchar     *confdir;

    /* create notebook */
    nbook = gtk_notebook_new ();
    gtk_notebook_set_scrollable (GTK_NOTEBOOK (nbook), TRUE);
    gtk_notebook_popup_enable (GTK_NOTEBOOK (nbook));
    g_object_set (G_OBJECT (nbook), "homogeneous", TRUE, NULL);
    g_signal_connect (G_OBJECT (nbook), "switch-page",
                      G_CALLBACK (switch_page_cb), NULL);

    /* get list of modules which should be open */
    openmods = sat_cfg_get_str (SAT_CFG_STR_OPEN_MODULES);

    if (openmods) {
        mods = g_strsplit (openmods, ";", 0);
        count = g_strv_length (mods);

        for (i = 0; i < count; i++) {

            /* get data file name */
            confdir = get_modules_dir ();
            modfile = g_strconcat (confdir, G_DIR_SEPARATOR_S,
                                   mods[i], ".mod", NULL);
            g_free (confdir);
            
            /* create module */
            module = gtk_sat_module_new (modfile);

            if (IS_GTK_SAT_MODULE (module)) {

                /* if module state was window or user does not want to restore the
                   state of the modules, pack the module into the notebook */
                if ((GTK_SAT_MODULE (module)->state == GTK_SAT_MOD_STATE_DOCKED) ||
                    !sat_cfg_get_bool (SAT_CFG_BOOL_MOD_STATE)) {

                    mod_mgr_add_module (module, TRUE);

                }
                else {
                    mod_mgr_add_module (module, FALSE);
                    create_module_window (module);
                }
            }
            else {
                sat_log_log (SAT_LOG_LEVEL_ERROR,
                             _("%s: Failed to restore %s"),
                             __FUNCTION__, mods[i]);
            }

            g_free (modfile);

        }

        g_strfreev (mods);
        g_free (openmods);

        /* disable tabs if only one page in notebook */
        if ((gtk_notebook_get_n_pages (GTK_NOTEBOOK(nbook))) == 1) {
            gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nbook), FALSE);
        }
        else {
            gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nbook), TRUE);
        }

    }
    else {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: No modules have to be restored."),
                     __FUNCTION__);
    }

    return nbook;
}
/** \brief Create and run GtkSatModule popup menu.
 *  \param module The module that should have the popup menu attached to it.
 *
 * This function ctreates and executes a popup menu that is related to a
 * GtkSatModule widget. The module must be a valid GtkSatModule, since it makes
 * no sense whatsoever to have this kind of popup menu without a GtkSatModule
 * parent.
 *
 */
void gtk_sat_module_popup (GtkSatModule *module)
{
    GtkWidget *menu;        /* The pop-up menu */
    GtkWidget *satsubmenu;  /* Satellite selection submenu */
    GtkWidget *menuitem;    /* Widget used to create the menu items */
    GtkWidget *image;       /* Widget used to create menu item icons */
    
    /* misc variables */
    GList  *sats;
    sat_t  *sat;
    gchar  *buff;
    guint   i,n;



    if ((module == NULL) || !IS_GTK_SAT_MODULE (module)) {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s:%d: %s called with NULL parameter!"),
                     __FILE__, __LINE__, __FUNCTION__);

        return;
    }

    menu = gtk_menu_new ();

    if (module->state == GTK_SAT_MOD_STATE_DOCKED) {

        menuitem = gtk_image_menu_item_new_with_label (_("Detach module"));
        buff = icon_file_name ("gpredict-notebook.png");
        image = gtk_image_new_from_file (buff);
        g_free (buff);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
        gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
        g_signal_connect (menuitem, "activate",
                          G_CALLBACK (docking_state_cb), module);
    }
    else {

        menuitem = gtk_image_menu_item_new_with_label (_("Attach module"));
        buff = icon_file_name ("gpredict-notebook.png");
        image = gtk_image_new_from_file (buff);
        g_free (buff);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
        gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
        g_signal_connect (menuitem, "activate",
                          G_CALLBACK (docking_state_cb), module);

    }

    if (module->state == GTK_SAT_MOD_STATE_FULLSCREEN) {

        menuitem = gtk_image_menu_item_new_with_label (_("Exit full screen"));
        image = gtk_image_new_from_stock (GTK_STOCK_LEAVE_FULLSCREEN,
                                          GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
        gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
        g_signal_connect (menuitem, "activate",
                          G_CALLBACK (screen_state_cb), module);
    }
    else {
        menuitem = gtk_image_menu_item_new_with_label (_("Full screen"));
        image = gtk_image_new_from_stock (GTK_STOCK_FULLSCREEN,
                                          GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
        gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
        g_signal_connect (menuitem, "activate",
                          G_CALLBACK (screen_state_cb), module);
    }

    /* separator */
    menuitem = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);

    /* select satellite submenu */
    menuitem = gtk_menu_item_new_with_label(_("Select satellite"));
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
    
    satsubmenu = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), satsubmenu);
    
    sats = g_hash_table_get_values(module->satellites);  
    sats = g_list_sort(sats , (GCompareFunc) sat_nickname_compare );

    n = g_list_length(sats);
    for (i = 0; i < n; i++) {
        sat = SAT(g_list_nth_data(sats, i));
        menuitem = gtk_menu_item_new_with_label(sat->nickname);
        g_object_set_data(G_OBJECT(menuitem), "catnum", GINT_TO_POINTER(sat->tle.catnr));
        g_signal_connect(menuitem, "activate", G_CALLBACK (sat_selected_cb), module);
        gtk_menu_shell_append(GTK_MENU_SHELL(satsubmenu), menuitem);
    }

    /* separator */
    menuitem = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);

    /* sky at a glance */
    menuitem = gtk_image_menu_item_new_with_label (_("Sky at a glance"));
    buff = icon_file_name ("gpredict-planner-small.png");
    image = gtk_image_new_from_file (buff);
    g_free (buff);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate",
                      G_CALLBACK (sky_at_glance_cb), module);

    /* time manager */
    menuitem = gtk_image_menu_item_new_with_label (_("Time Controller"));
    buff = icon_file_name ("gpredict-clock-small.png");
    image = gtk_image_new_from_file (buff);
    g_free (buff);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate", G_CALLBACK (tmgr_cb), module);
    
    /* separator */
    menuitem = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);

    /* Radio Control */
    menuitem = gtk_image_menu_item_new_with_label (_("Radio Control"));
    buff = icon_file_name ("gpredict-oscilloscope-small.png");
    image = gtk_image_new_from_file (buff);
    g_free (buff);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate", G_CALLBACK (rigctrl_cb), module);
    
    /* Antenna Control */
    menuitem = gtk_image_menu_item_new_with_label (_("Antenna Control"));
    buff = icon_file_name ("gpredict-antenna-small.png");
    image = gtk_image_new_from_file (buff);
    g_free (buff);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate", G_CALLBACK (rotctrl_cb), module);

    /* separator */
    menuitem = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);

    /* configure */
    menuitem = gtk_image_menu_item_new_with_label (_("Configure"));
    image = gtk_image_new_from_stock (GTK_STOCK_PROPERTIES,
                                      GTK_ICON_SIZE_MENU);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate",
                      G_CALLBACK (config_cb), module);

    /* clone */
    menuitem = gtk_image_menu_item_new_with_label (_("Clone..."));
    image = gtk_image_new_from_stock (GTK_STOCK_COPY,
                                      GTK_ICON_SIZE_MENU);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate",
                      G_CALLBACK (clone_cb), module);

    /* separator */
    menuitem = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);

    /* delete module */
    menuitem = gtk_image_menu_item_new_with_label (_("Delete"));
    image = gtk_image_new_from_stock (GTK_STOCK_DELETE,
                                      GTK_ICON_SIZE_MENU);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate",
                      G_CALLBACK (delete_cb), module);

    /* close */
    menuitem = gtk_image_menu_item_new_with_label (_("Close"));
    image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
                                      GTK_ICON_SIZE_MENU);
    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
    gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
    g_signal_connect (menuitem, "activate",
                      G_CALLBACK (close_cb), module);

    gtk_widget_show_all (menu);

    gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
                    0, gdk_event_get_time (NULL));
}