コード例 #1
0
ファイル: recentmanager.c プロジェクト: Aridna/gtk2
static void
recent_manager_add (void)
{
  GtkRecentManager *manager;
  GtkRecentData *recent_data;
  gboolean res;

  manager = gtk_recent_manager_get_default ();

  recent_data = g_slice_new0 (GtkRecentData);

  /* mime type is mandatory */
  recent_data->mime_type = NULL;
  recent_data->app_name = "testrecentchooser";
  recent_data->app_exec = "testrecentchooser %u";
  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
    {
      res = gtk_recent_manager_add_full (manager,
                                         uri,
                                         recent_data);
    }
  g_test_trap_assert_failed ();

  /* app name is mandatory */
  recent_data->mime_type = "text/plain";
  recent_data->app_name = NULL;
  recent_data->app_exec = "testrecentchooser %u";
  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
    {
      res = gtk_recent_manager_add_full (manager,
                                         uri,
                                         recent_data);
    }
  g_test_trap_assert_failed ();

  /* app exec is mandatory */
  recent_data->mime_type = "text/plain";
  recent_data->app_name = "testrecentchooser";
  recent_data->app_exec = NULL;
  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
    {
      res = gtk_recent_manager_add_full (manager,
                                         uri,
                                         recent_data);
    }
  g_test_trap_assert_failed ();

  recent_data->mime_type = "text/plain";
  recent_data->app_name = "testrecentchooser";
  recent_data->app_exec = "testrecentchooser %u";
  res = gtk_recent_manager_add_full (manager,
                                     uri,
                                     recent_data);
  g_assert (res == TRUE);

  g_slice_free (GtkRecentData, recent_data);
}
コード例 #2
0
ファイル: application.c プロジェクト: UIKit0/gnumeric
/**
 * application_history_update_list:
 * @uri:
 *
 * Adds @uri to the application's history of files.
 **/
void
gnm_app_history_add (char const *uri, const char *mimetype)
{
	GtkRecentData rd;

	if (app->recent == NULL)
		return;

	memset (&rd, 0, sizeof (rd));

#if 0
	g_print ("uri: %s\nmime: %s\n\n", uri, mimetype ? mimetype : "-");
#endif

        rd.mime_type =
		g_strdup (mimetype ? mimetype : "application/octet-stream");

	rd.app_name = g_strdup (g_get_application_name ());
	rd.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
	rd.groups = NULL;
	rd.is_private = FALSE;

	if (!gtk_recent_manager_add_full (app->recent, uri, &rd)) {
		/* Now what?  */
		g_printerr ("Warning: failed to update recent document.\n");
	}

	g_free (rd.mime_type);
	g_free (rd.app_name);
	g_free (rd.app_exec);

	g_object_notify (G_OBJECT (app), "file-history-list");
}
コード例 #3
0
ファイル: pragha-file-utils.c プロジェクト: TingPing/pragha
static void
add_recent_file (const gchar *filename)
{
	GtkRecentData recent_data;
	gchar *uri = NULL;

#ifdef G_OS_WIN32
	recent_data.mime_type = get_mime_type_from_uri (filename, NULL);
#else
	recent_data.mime_type = get_mime_type (filename);
#endif

	if (recent_data.mime_type == NULL)
		return;

	recent_data.display_name = g_filename_display_basename (filename);
	recent_data.app_name = g_strdup (g_get_application_name ());
	recent_data.app_exec =  g_strjoin (" ", g_get_prgname (), "%u", NULL);
	recent_data.description = NULL;
	recent_data.groups = NULL;
	recent_data.is_private = FALSE;

	uri = g_filename_to_uri(filename, NULL, NULL);
	gtk_recent_manager_add_full(gtk_recent_manager_get_default(), uri, &recent_data);

	g_free (recent_data.display_name);
	g_free (recent_data.mime_type);
	g_free (recent_data.app_name);
	g_free (recent_data.app_exec);
	g_free (uri);
}
コード例 #4
0
ファイル: recentmanager.c プロジェクト: Aridna/gtk2
static void
recent_manager_purge (void)
{
  GtkRecentManager *manager;
  GtkRecentData *recent_data;
  gint n;
  GError *error;

  manager = gtk_recent_manager_get_default ();

  /* purge, add 1, purge again and check that 1 item has been purged */
  error = NULL;
  n = gtk_recent_manager_purge_items (manager, &error);
  g_assert (error == NULL);

  recent_data = g_slice_new0 (GtkRecentData);
  recent_data->mime_type = "text/plain";
  recent_data->app_name = "testrecentchooser";
  recent_data->app_exec = "testrecentchooser %u";
  gtk_recent_manager_add_full (manager, uri, recent_data);
  g_slice_free (GtkRecentData, recent_data);

  error = NULL;
  n = gtk_recent_manager_purge_items (manager, &error);
  g_assert (error == NULL);
  g_assert (n == 1);
}
コード例 #5
0
static void
set_recent_entry (ScreenshotApplication *self)
{
  char *app_exec = NULL;
  GtkRecentManager *recent;
  GtkRecentData recent_data;
  GAppInfo *app;
  const char *exec_name = NULL;
  static char * groups[2] = { "Graphics", NULL };

  app = g_app_info_get_default_for_type ("image/png", TRUE);

  if (!app) {
    /* return early, as this would be an useless recent entry anyway. */
    return;
  }

  recent = gtk_recent_manager_get_default ();
  
  exec_name = g_app_info_get_executable (app);
  app_exec = g_strjoin (" ", exec_name, "%u", NULL);

  recent_data.display_name = NULL;
  recent_data.description = NULL;
  recent_data.mime_type = "image/png";
  recent_data.app_name = "GNOME Screenshot";
  recent_data.app_exec = app_exec;
  recent_data.groups = groups;
  recent_data.is_private = FALSE;

  gtk_recent_manager_add_full (recent, self->priv->save_uri, &recent_data);

  g_object_unref (app);
  g_free (app_exec);
}
コード例 #6
0
ファイル: RecentManager.cpp プロジェクト: wbrenna/xournalpp
void RecentManager::addRecentFileUri(const char * uri) {
	XOJ_CHECK_TYPE(RecentManager);

	printf("addRecentFileUri: %s\n", uri);

	GtkRecentManager * recentManager;
	GtkRecentData * recentData;

	static gchar * groups[2] = { g_strdup(GROUP), NULL };

	recentManager = gtk_recent_manager_get_default();

	recentData = g_slice_new(GtkRecentData);

	recentData->display_name = NULL;
	recentData->description = NULL;

	if (g_str_has_suffix(uri, ".pdf")) {
		recentData->mime_type = (gchar *) g_strdup(MIME_PDF);
	} else {
		recentData->mime_type = (gchar *) g_strdup(MIME);
	}

	recentData->app_name = (gchar *) g_get_application_name();
	recentData->app_exec = g_strjoin(" ", g_get_prgname(), "%u", NULL);
	recentData->groups = groups;
	recentData->is_private = FALSE;

	gtk_recent_manager_add_full(recentManager, uri, recentData);

	g_free(recentData->app_exec);

	g_slice_free(GtkRecentData, recentData);
}
コード例 #7
0
ファイル: gtkfilebutton.c プロジェクト: glaubitz/kcemu-debian
static void
add_recent_info(const gchar *filename, const gchar *group)
{
  GtkRecentManager *manager = gtk_recent_manager_get_default();

  GFile *file = g_file_new_for_path(filename);
  gchar *uri = g_file_get_uri(file);
  g_object_unref(file);

  gchar *groups[2];
  GtkRecentData recent_data;
  memset(&recent_data, 0, sizeof(recent_data));
  recent_data.mime_type = "application/octet-stream";
  recent_data.app_name = "KCemu";
  recent_data.app_exec = "xdg-open %u";
  if (group != NULL)
    {
      recent_data.groups = groups;
      recent_data.groups[0] = (gchar*)group;
      recent_data.groups[1] = NULL;
    }

  gtk_recent_manager_add_full(manager, uri, &recent_data);
  g_free(uri);
}
コード例 #8
0
ファイル: main.c プロジェクト: jcape/gnoMint
void __recent_add_utf8_filename (const gchar *utf8_filename)
{
        GtkRecentData *recent_data;
        gchar         *filename;
        gchar         *uri;
	gchar         *pwd;

        static gchar *groups[2] = {
                "gnomint",
                NULL
        };


        recent_data = g_slice_new (GtkRecentData);

        recent_data->display_name = NULL;
        recent_data->description  = NULL;
        recent_data->mime_type    = GNOMINT_MIME_TYPE;
        recent_data->app_name     = (gchar *) g_get_application_name ();
        recent_data->app_exec     = g_strjoin (" ", g_get_prgname (), "%f", NULL);
        recent_data->groups       = groups;
        recent_data->is_private = FALSE;

        filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
        if ( filename != NULL )
        {

		if (! g_path_is_absolute (filename)) {
			gchar *absolute_filename;

			pwd = g_get_current_dir ();
			absolute_filename = g_build_filename (pwd, filename, NULL);
			g_free (pwd);
			g_free (filename);
			filename = absolute_filename;
		}


                uri = g_filename_to_uri (filename, NULL, NULL);
                if ( uri != NULL )
                {

                        gtk_recent_manager_add_full (recent_manager, uri, recent_data);
                        g_free (uri);

                }
                g_free (filename);

        }

        g_free (recent_data->app_exec);
        g_slice_free (GtkRecentData, recent_data);

}
static void
swfdec_window_player_initialized (SwfdecPlayer *player, GParamSpec *pspec, SwfdecWindow *window)
{
  static const char *mime[2] = { "swfdec-player", NULL };
  GtkRecentData data = { NULL, NULL, (char *) "application/x-shockwave-flash",
    (char *) g_get_application_name (), g_strjoin (" ", g_get_prgname (), "%u", NULL), 
    (char **) mime, FALSE };

  if (swfdec_player_is_initialized (player)) {
    gtk_recent_manager_add_full (gtk_recent_manager_get_default (),
	swfdec_url_get_url (swfdec_loader_get_url (window->loader)),
	&data);
    g_signal_handlers_disconnect_by_func (player, swfdec_window_player_next_event, window);
  }
  g_free (data.app_exec);
}
コード例 #10
0
ファイル: gedit-recent.c プロジェクト: tschoonj/gedit
void
gedit_recent_add_document (GeditDocument *document)
{
    GtkRecentManager *recent_manager;
    GtkRecentData *recent_data;
    GtkSourceFile *file;
    GFile *location;
    gchar *uri;

    g_return_if_fail (GEDIT_IS_DOCUMENT (document));

    static gchar *groups[2] = {
        "gedit",
        NULL
    };

    file = gedit_document_get_file (document);
    location = gtk_source_file_get_location (file);

    if (location != NULL)
    {
        recent_manager = gtk_recent_manager_get_default ();

        recent_data = g_slice_new (GtkRecentData);

        recent_data->display_name = NULL;
        recent_data->description = NULL;
        recent_data->mime_type = gedit_document_get_mime_type (document);
        recent_data->app_name = (gchar *) g_get_application_name ();
        recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
        recent_data->groups = groups;
        recent_data->is_private = FALSE;

        uri = g_file_get_uri (location);

        if (!gtk_recent_manager_add_full (recent_manager, uri, recent_data))
        {
            g_warning ("Failed to add uri '%s' to the recent manager.", uri);
        }

        g_free (uri);
        g_free (recent_data->app_exec);
        g_free (recent_data->mime_type);
        g_slice_free (GtkRecentData, recent_data);
    }
}
コード例 #11
0
static VALUE
rg_add_item(int argc, VALUE *argv, VALUE self)
{
    VALUE uri, data;
    gboolean ret;
    rb_scan_args(argc, argv, "11", &uri, &data);

    if (NIL_P(data)){
        ret = gtk_recent_manager_add_item(_SELF(self), RVAL2CSTR(uri));
        if (! ret) rb_raise(rb_eRuntimeError, "Can't add the uri");
    } else {
        ret = gtk_recent_manager_add_full(_SELF(self),
                                          RVAL2CSTR(uri),
                                          RVAL2BOXED(data, GTK_TYPE_RECENT_DATA));
        if (! ret) rb_raise(rb_eRuntimeError, "Can't add the uri or data");
    }
    return self;
}
コード例 #12
0
ファイル: nautilus-recent.c プロジェクト: Abdillah/nautilus
void
nautilus_recent_add_file (NautilusFile *file,
			  GAppInfo *application)
{
	GtkRecentData recent_data;
	char *uri;

	uri = nautilus_file_get_activation_uri (file);
	if (uri == NULL) {
		uri = nautilus_file_get_uri (file);
	}

	/* do not add trash:// etc */
	if (eel_uri_is_trash (uri)  ||
	    eel_uri_is_search (uri) ||
	    eel_uri_is_recent (uri) ||
	    eel_uri_is_desktop (uri)) {
		g_free (uri);
		return;
	}

	recent_data.display_name = NULL;
	recent_data.description = NULL;

	recent_data.mime_type = nautilus_file_get_mime_type (file);
	recent_data.app_name = g_strdup (g_get_application_name ());

	if (application != NULL)
		recent_data.app_exec = g_strdup (g_app_info_get_commandline (application));
	else
		recent_data.app_exec = g_strdup (DEFAULT_APP_EXEC);

	recent_data.groups = NULL;
	recent_data.is_private = FALSE;

	gtk_recent_manager_add_full (nautilus_recent_get_manager (),
				     uri, &recent_data);

	g_free (recent_data.mime_type);
	g_free (recent_data.app_name);
	g_free (recent_data.app_exec);
	
	g_free (uri);
}
コード例 #13
0
ファイル: glide-window.c プロジェクト: racarr/Glide
static void
glide_window_document_path_changed_cb (GObject *object,
				       GParamSpec *pspec,
				       gpointer user_data)
{
  GlideWindow *w = (GlideWindow *)user_data;
  const gchar *path = glide_document_get_path (w->priv->document);
  gchar *uri = g_strdup_printf("file://%s",path);
  GtkRecentData rd = { 0, };
  
  glide_window_update_title (w);
  
  rd.mime_type = "application-x/glide";
  rd.app_name = "Glide";
  rd.app_exec = "glide %f";

  gtk_recent_manager_add_full (w->priv->recent_manager, uri, &rd);
  g_free (uri);
}
コード例 #14
0
ファイル: gitg-window.c プロジェクト: mpe/gitg
static void
add_recent_item(GitgWindow *window)
{
	GtkRecentManager *manager = gtk_recent_manager_get_default();
	GtkRecentData data = { 0 };
	gchar *groups[] = {"gitg", NULL};
	gchar const *path = gitg_repository_get_path(window->priv->repository);
	gchar *basename = g_path_get_basename(path);
	
	data.display_name = basename;
	data.app_name = "gitg";
	data.mime_type = "inode/directory";
	data.app_exec = "gitg %f";
	data.groups = groups;

	GFile *file = g_file_new_for_path(gitg_repository_get_path(window->priv->repository));
	gchar *uri = g_file_get_uri(file);
	gtk_recent_manager_add_full(manager, uri, &data);
	
	g_free(basename);
	g_free(uri);
	g_object_unref(file);
}
コード例 #15
0
static void
recent_add(gchar *uri, const gchar *mime_type)
{
    GtkRecentManager *recent;
    GtkRecentData meta = {
        .app_name     = (char*)"remote-viewer",
        .app_exec     = (char*)"remote-viewer %u",
        .mime_type    = (char*)mime_type,
    };

    if (uri == NULL)
        return;

    recent = gtk_recent_manager_get_default();
    meta.display_name = uri;
    if (!gtk_recent_manager_add_full(recent, uri, &meta))
        g_warning("Recent item couldn't be added");
}

static void connected(VirtViewerSession *session,
                      VirtViewerApp *self G_GNUC_UNUSED)
{
    gchar *uri = virt_viewer_session_get_uri(session);
    const gchar *mime = virt_viewer_session_mime_type(session);

    recent_add(uri, mime);
    g_free(uri);
}

//char buffer[1024]={0}; 
struct remote_viewer_data rvdata;
int connectflag;
/////////////////////
//socket here declare
int cfd;				/*connecting socket*/
int recbytes;
int isn_size;
struct sockaddr_in s_add, c_add;
unsigned short portnum = 6666;
///////////////////////
int
main(int argc, char **argv)
{
/*
int cfd;
int recbytes;
int sin_size;
struct sockaddr_in s_add,c_add;
unsigned short portnum=6666; 
*/
//print***
printf("Hello,welcome to client !\r\n");
memset(&rvdata, 0 , sizeof(rvdata));

cfd = socket(AF_INET, SOCK_STREAM, 0);
if(-1 == cfd)
{
	//print***
    printf("socket fail ! \r\n");
    return -1;
}
//print***
printf("socket ok !\r\n");

bzero(&s_add,sizeof(struct sockaddr_in));
s_add.sin_family=AF_INET;

//获取本机IP
//
char localeIp[32];
struct ifaddrs * ifAddrStruct=NULL;

     void * tmpAddrPtr=NULL;
     getifaddrs(&ifAddrStruct);
     while (ifAddrStruct!=NULL)
	 {
         if (ifAddrStruct->ifa_addr->sa_family==AF_INET)
			{ // check it is IP4
             // is a valid IP4 Address
				tmpAddrPtr=&((struct sockaddr_in *)ifAddrStruct->ifa_addr)->sin_addr;
				char addressBuffer[INET_ADDRSTRLEN];
				inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
				printf("\n%s\n",ifAddrStruct->ifa_name);
				if(strcmp(ifAddrStruct->ifa_name,"eth0") == 0)
				{
					printf("i need IP:%s\n",addressBuffer);
					strcpy(localeIp, addressBuffer);
					localeIp[strlen(addressBuffer)] = '\0';
				}
				printf("%s IP Address %s\n", ifAddrStruct->ifa_name, addressBuffer); 
			} 
		 else if (ifAddrStruct->ifa_addr->sa_family==AF_INET6)
		 { 	// check it is IP6
             // is a valid IP6 Address
             tmpAddrPtr=&((struct sockaddr_in *)ifAddrStruct->ifa_addr)->sin_addr;
             char addressBuffer[INET6_ADDRSTRLEN];
             inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
             printf("%s IP Address %s\n", ifAddrStruct->ifa_name, addressBuffer); 
         } 
         ifAddrStruct=ifAddrStruct->ifa_next;
     }
////////////////////////////////////

s_add.sin_addr.s_addr= inet_addr(localeIp);//应该改为获取本机IP获取作为参数传递
s_add.sin_port=htons(portnum);
//print***
printf("s_addr = %#x ,port : %#x\r\n",s_add.sin_addr.s_addr,s_add.sin_port);

//发送连接请求知道服务器响应连接
while (1)
{
	if(0 == connect(cfd,(struct sockaddr *)(&s_add), sizeof(struct sockaddr)))
	{
	    break;
	}
}
//print***
printf("connect ok !\r\n");

//接收服务器发送的需连接的虚拟机IP地址
if(-1 == (recbytes = read(cfd,&rvdata,sizeof(rvdata))))		/*@modify by yl*/
{
	//print***
    printf("read data fail !\r\n");
    return -1;
}
//print***
printf("read ok\r\nREC:\r\n");
//buffer[recbytes]='\0';
//print***
//printf("Buffer:%s\r\n",buffer);
printf("ip_str:%s\n", rvdata.ip_str);

///////////////////////////////////////////////////
    GOptionContext *context;
    GError *error = NULL;
    int ret = 1;
    gchar **args = NULL;
    gchar *uri = NULL;
    char *title = NULL;
    RemoteViewer *viewer = NULL;
#ifdef HAVE_SPICE_GTK
    gboolean controller = FALSE;
#endif
    VirtViewerApp *app;
    const GOptionEntry options [] = {
        { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
          remote_viewer_version, N_("Display version information"), NULL },
        { "title", 't', 0, G_OPTION_ARG_STRING, &title,
          N_("Set window title"), NULL },
#ifdef HAVE_SPICE_GTK
        { "spice-controller", '\0', 0, G_OPTION_ARG_NONE, &controller,
          N_("Open connection using Spice controller communication"), NULL },
#endif
        { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
          NULL, "-- URI" },
        { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
    };

    virt_viewer_util_init(_("Remote Viewer"));

    /* Setup command line options */
    context = g_option_context_new (_("- Remote viewer client"));
    g_option_context_add_main_entries (context, virt_viewer_app_get_options(), NULL);
    g_option_context_add_main_entries (context, options, NULL);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
#ifdef HAVE_GTK_VNC
    g_option_context_add_group (context, vnc_display_get_option_group ());
#endif
#ifdef HAVE_SPICE_GTK
    g_option_context_add_group (context, spice_get_option_group ());
#endif
#ifdef HAVE_OVIRT
    g_option_context_add_group (context, ovirt_get_option_group ());
#endif
    g_option_context_parse (context, &argc, &argv, &error);
    if (error) {
        char *base_name;
        base_name = g_path_get_basename(argv[0]);
        g_printerr(_("%s\nRun '%s --help' to see a full list of available command line options\n"),
                   error->message, base_name);
        g_free(base_name);
        g_error_free(error);
        goto cleanup;
    }

    g_option_context_free(context);

#ifdef HAVE_SPICE_GTK
    if (controller) {
        if (args) {
            g_printerr(_("Error: extra arguments given while using Spice controller\n"));
            goto cleanup;
        }
    } else
#endif
    if (args) {
        if (g_strv_length(args) > 1) {
            g_printerr(_("Error: can't handle multiple URIs\n"));
            goto cleanup;
        } else if (g_strv_length(args) == 1) {
            uri = g_strdup(args[0]);
        }
    }

#ifdef HAVE_SPICE_GTK
    if (controller) {
        viewer = remote_viewer_new_with_controller();
        g_object_set(viewer, "guest-name", "defined by Spice controller", NULL);
    } else {
#endif
        viewer = remote_viewer_new(uri, title);
        g_object_set(viewer, "guest-name", uri, NULL);
#ifdef HAVE_SPICE_GTK
    }
#endif
    if (viewer == NULL)
        goto cleanup;

    app = VIRT_VIEWER_APP(viewer);

    if (!virt_viewer_app_start(app))
        goto cleanup;

    g_signal_connect(virt_viewer_app_get_session(app), "session-connected",
                     G_CALLBACK(connected), app);

    gtk_main();

    ret = 0;

 cleanup:
    g_free(uri);
    if (viewer)
        g_object_unref(viewer);
    g_strfreev(args);

///////////////////////////////////////
//连接虚出move to Error widget showing
/*
    if (1 == connectflag)
	write(cfd, "false", 6);
    else
	write(cfd, "true", 5);

close(cfd);
*/
///////////////////////////////////////

    return ret;
}
コード例 #16
0
static void
recent_add(gchar *uri, const gchar *mime_type)
{
    GtkRecentManager *recent;
    GtkRecentData meta = {
        .app_name     = (char*)"remote-viewer",
        .app_exec     = (char*)"remote-viewer %u",
        .mime_type    = (char*)mime_type,
    };

    if (uri == NULL)
        return;

    recent = gtk_recent_manager_get_default();
    meta.display_name = uri;
    if (!gtk_recent_manager_add_full(recent, uri, &meta))
        g_warning("Recent item couldn't be added");
}

static void connected(VirtViewerSession *session,
                      VirtViewerApp *self G_GNUC_UNUSED)
{
    gchar *uri = virt_viewer_session_get_uri(session);
    const gchar *mime = virt_viewer_session_mime_type(session);

    recent_add(uri, mime);
    g_free(uri);
}

int
main(int argc, char **argv)
{
    GOptionContext *context;
    GError *error = NULL;
    int ret = 1;
    gchar **args = NULL;
    gchar *uri = NULL;
    char *title = NULL;
    RemoteViewer *viewer = NULL;
#ifdef HAVE_SPICE_GTK
    gboolean controller = FALSE;
#endif
    VirtViewerApp *app;
    const GOptionEntry options [] = {
        {   "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
            remote_viewer_version, N_("Display version information"), NULL
        },
        {   "title", 't', 0, G_OPTION_ARG_STRING, &title,
            N_("Set window title"), NULL
        },
#ifdef HAVE_SPICE_GTK
        {   "spice-controller", '\0', 0, G_OPTION_ARG_NONE, &controller,
            N_("Open connection using Spice controller communication"), NULL
        },
#endif
        {   G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
            NULL, "-- URI"
        },
        { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
    };

    virt_viewer_util_init(_("Remote Viewer"));

    /* Setup command line options */
    context = g_option_context_new (_("- Remote viewer client"));
    g_option_context_add_main_entries (context, virt_viewer_app_get_options(), NULL);
    g_option_context_add_main_entries (context, options, NULL);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
#ifdef HAVE_GTK_VNC
    g_option_context_add_group (context, vnc_display_get_option_group ());
#endif
#ifdef HAVE_SPICE_GTK
    g_option_context_add_group (context, spice_get_option_group ());
#endif
#ifdef HAVE_OVIRT
    g_option_context_add_group (context, ovirt_get_option_group ());
#endif
    g_option_context_parse (context, &argc, &argv, &error);
    if (error) {
        char *base_name;
        base_name = g_path_get_basename(argv[0]);
        g_printerr(_("%s\nRun '%s --help' to see a full list of available command line options\n"),
                   error->message, base_name);
        g_free(base_name);
        g_error_free(error);
        goto cleanup;
    }

    g_option_context_free(context);

#ifdef HAVE_SPICE_GTK
    if (controller) {
        if (args) {
            g_printerr(_("Error: extra arguments given while using Spice controller\n"));
            goto cleanup;
        }
    } else
#endif
        if (args) {
            if (g_strv_length(args) > 1) {
                g_printerr(_("Error: can't handle multiple URIs\n"));
                goto cleanup;
            } else if (g_strv_length(args) == 1) {
                uri = g_strdup(args[0]);
            }
        }

#ifdef HAVE_SPICE_GTK
    if (controller) {
        viewer = remote_viewer_new_with_controller();
        g_object_set(viewer, "guest-name", "defined by Spice controller", NULL);
    } else {
#endif
        viewer = remote_viewer_new(uri);
        if (title)
            g_object_set(viewer, "title", title, NULL);
#ifdef HAVE_SPICE_GTK
    }
#endif
    if (viewer == NULL)
        goto cleanup;

    app = VIRT_VIEWER_APP(viewer);

    if (!virt_viewer_app_start(app))
        goto cleanup;

    g_signal_connect(virt_viewer_app_get_session(app), "session-connected",
                     G_CALLBACK(connected), app);

    gtk_main();

    ret = 0;

cleanup:
    g_free(uri);
    if (viewer)
        g_object_unref(viewer);
    g_strfreev(args);

    return ret;
}
コード例 #17
0
ファイル: main.c プロジェクト: kfreytag/dat-player
gint play_iter(GtkTreeIter * playiter, gint restart_second)
{

    gchar *subtitle = NULL;
    gchar *audiofile = NULL;
    GtkTreePath *path;
    gchar *uri = NULL;
    gint count;
    gint playlist;
    gchar *title = NULL;
    gchar *artist = NULL;
    gchar *album = NULL;
    gchar *audio_codec;
    gchar *video_codec = NULL;
    GtkAllocation alloc;
    gchar *demuxer = NULL;
    gboolean playable = TRUE;
    gint width;
    gint height;
    gfloat length_value;
    gint i;
    gpointer pixbuf;
    gchar *buffer = NULL;
    gchar *message = NULL;
    MetaData *metadata;
#ifdef GTK2_12_ENABLED
    GtkRecentData *recent_data;
#ifdef GIO_ENABLED
    GFile *file;
    GFileInfo *file_info;
#endif
#endif

    /*
       if (!(gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) == MEDIA_STATE_UNKNOWN ||
       gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) == MEDIA_STATE_QUIT)) {
       while (gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) != MEDIA_STATE_UNKNOWN) {
       gtk_main_iteration();
       }
       }
     */

    if (gtk_list_store_iter_is_valid(playliststore, playiter)) {
        gtk_tree_model_get(GTK_TREE_MODEL(playliststore), playiter, ITEM_COLUMN, &uri,
                           DESCRIPTION_COLUMN, &title, LENGTH_VALUE_COLUMN, &length_value,
                           ARTIST_COLUMN, &artist,
                           ALBUM_COLUMN, &album,
                           AUDIO_CODEC_COLUMN, &audio_codec,
                           VIDEO_CODEC_COLUMN, &video_codec,
                           VIDEO_WIDTH_COLUMN, &width,
                           VIDEO_HEIGHT_COLUMN, &height,
                           DEMUXER_COLUMN, &demuxer,
                           COVERART_COLUMN, &pixbuf,
                           SUBTITLE_COLUMN, &subtitle,
                           AUDIOFILE_COLUMN, &audiofile,
                           COUNT_COLUMN, &count, PLAYLIST_COLUMN, &playlist, PLAYABLE_COLUMN, &playable, -1);
        if (GTK_IS_TREE_SELECTION(selection)) {
            path = gtk_tree_model_get_path(GTK_TREE_MODEL(playliststore), playiter);
            if (path) {
                gtk_tree_selection_select_path(selection, path);
                if (GTK_IS_WIDGET(list))
                    gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(list), path, NULL, FALSE, 0, 0);
                buffer = gtk_tree_path_to_string(path);
                g_free(buffer);
                gtk_tree_path_free(path);
            }
        }
        gtk_list_store_set(playliststore, playiter, COUNT_COLUMN, count + 1, -1);
    } else {
        if (verbose > 1)
            printf("iter is invalid, nothing to play\n");
        return 0;
    }

    if (verbose) {
        printf("playing - %s\n", uri);
        printf("is playlist %i\n", playlist);
    }

    gmtk_get_allocation(GTK_WIDGET(media), &alloc);
    if (width == 0 || height == 0) {
        alloc.width = 16;
        alloc.height = 16;
    } else {
        alloc.width = width;
        alloc.height = height;
    }
    //printf("setting window size to %i x %i\n", alloc.width, alloc.height);
    gtk_widget_size_allocate(GTK_WIDGET(media), &alloc);
    while (gtk_events_pending())
        gtk_main_iteration();

    /*
       // wait for metadata to be available on this item
       if (!streaming_media(uri) && !device_name(uri)) {
       i = 0;
       if (playable) {
       while (demuxer == NULL && i < 50) {
       g_free(title);
       g_free(artist);
       g_free(album);
       g_free(audio_codec);
       g_free(video_codec);
       g_free(demuxer);
       g_free(subtitle);
       g_free(audiofile);
       if (gtk_list_store_iter_is_valid(playliststore, playiter)) {
       gtk_tree_model_get(GTK_TREE_MODEL(playliststore), playiter, LENGTH_VALUE_COLUMN,
       &length_value, DESCRIPTION_COLUMN, &title, ARTIST_COLUMN,
       &artist, ALBUM_COLUMN, &album, AUDIO_CODEC_COLUMN,
       &audio_codec, VIDEO_CODEC_COLUMN, &video_codec,
       VIDEO_WIDTH_COLUMN, &width, VIDEO_HEIGHT_COLUMN, &height,
       DEMUXER_COLUMN, &demuxer, COVERART_COLUMN, &pixbuf,
       SUBTITLE_COLUMN, &subtitle, AUDIOFILE_COLUMN, &audiofile,
       COUNT_COLUMN, &count, PLAYLIST_COLUMN, &playlist,
       PLAYABLE_COLUMN, &playable, -1);
       if (!playable) {
       if (verbose)
       printf("%s is not marked as playable (%i)\n", uri, i);
       play_next();
       return 0;
       }
       } else {
       if (verbose)
       printf("Current iter is not valid\n");
       return 1;   // error condition
       }
       gtk_main_iteration();
       i++;
       if (demuxer == NULL)
       g_usleep(10000);
       }
       } else {
       if (verbose)
       printf("%s is not marked as playable\n", uri);
       play_next();
       return 0;
       }

       }
     */
    // reset audio meter
    for (i = 0; i < METER_BARS; i++) {
        buckets[i] = 0;
        max_buckets[i] = 0;
    }

    gmtk_media_tracker_set_text(tracker, _("Playing"));
    gmtk_media_tracker_set_position(tracker, (gfloat) restart_second);
    gmtk_media_tracker_set_length(tracker, length_value);

    message = g_strdup_printf("<small>\n");
    if (title == NULL) {
        title = g_filename_display_basename(uri);
    }
    buffer = g_markup_printf_escaped("\t<big><b>%s</b></big>\n", title);
    message = g_strconcat(message, buffer, NULL);
    g_free(buffer);

    if (artist != NULL) {
        buffer = g_markup_printf_escaped("\t<i>%s</i>\n", artist);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    if (album != NULL) {
        buffer = g_markup_printf_escaped("\t%s\n", album);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    //buffer = g_markup_printf_escaped("\n\t%s\n", uri);
    //message = g_strconcat(message, buffer, NULL);
    //g_free(buffer);

    message = g_strconcat(message, "</small>", NULL);

    // probably not much cover art for random video files
    if (pixbuf == NULL && video_codec == NULL && !streaming_media(uri) && control_id == 0 && !playlist) {
        metadata = (MetaData *) g_new0(MetaData, 1);
        metadata->uri = g_strdup(uri);
        if (title != NULL)
            metadata->title = g_strstrip(g_strdup(title));
        if (artist != NULL)
            metadata->artist = g_strstrip(g_strdup(artist));
        if (album != NULL)
            metadata->album = g_strstrip(g_strdup(album));
        g_thread_create(get_cover_art, metadata, FALSE, NULL);
    } else {
        gtk_image_clear(GTK_IMAGE(cover_art));
    }

    g_strlcpy(idledata->media_info, message, 1024);
    g_strlcpy(idledata->display_name, title, 1024);
    g_free(message);

    message = gm_tempname(NULL, "mplayer-af_exportXXXXXX");
    g_strlcpy(idledata->af_export, message, 1024);
    g_free(message);

    message = g_strdup("");
    if (title == NULL) {
        title = g_filename_display_basename(uri);
    }
    //buffer = g_markup_printf_escaped("\t<b>%s</b>\n", title);
    //message = g_strconcat(message, buffer, NULL);
    //g_free(buffer);

    if (artist != NULL) {
        buffer = g_markup_printf_escaped("\t<i>%s</i>\n", artist);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    if (album != NULL) {
        buffer = g_markup_printf_escaped("\t%s\n", album);
        message = g_strconcat(message, buffer, NULL);
        g_free(buffer);
    }
    g_strlcpy(idledata->media_notification, message, 1024);
    g_free(message);

    if (control_id == 0) {
        set_media_label(idledata);
    } else {
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem_view_info), FALSE);
    }

    if (subtitles)
        gtk_container_forall(GTK_CONTAINER(subtitles), remove_langs, NULL);
    gtk_widget_set_sensitive(GTK_WIDGET(menuitem_edit_select_sub_lang), FALSE);
    if (tracks)
        gtk_container_forall(GTK_CONTAINER(tracks), remove_langs, NULL);
    gtk_widget_set_sensitive(GTK_WIDGET(menuitem_edit_select_audio_lang), FALSE);
    lang_group = NULL;
    audio_group = NULL;


    if (subtitle != NULL) {
        gmtk_media_player_set_attribute_string(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_SUBTITLE_FILE, subtitle);
        g_free(subtitle);
        subtitle = NULL;
    }
    if (audiofile != NULL) {
        gmtk_media_player_set_attribute_string(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_AUDIO_TRACK_FILE, audiofile);
        g_free(audiofile);
        audiofile = NULL;
    }

    /*
       if (g_ascii_strcasecmp(thread_data->filename, "") != 0) {
       if (!device_name(thread_data->filename) && !streaming_media(thread_data->filename)) {
       if (!g_file_test(thread_data->filename, G_FILE_TEST_EXISTS)) {
       error_msg = g_strdup_printf("%s not found\n", thread_data->filename);
       dialog =
       gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
       GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error_msg);
       gtk_window_set_title(GTK_WINDOW(dialog), "GNOME MPlayer Error");
       gtk_dialog_run(GTK_DIALOG(dialog));
       gtk_widget_destroy(dialog);
       return 1;
       }
       }
       }
     */
#ifdef GTK2_12_ENABLED
#ifdef GIO_ENABLED
    // don't put it on the recent list, if it is running in plugin mode
    if (control_id == 0 && !streaming_media(uri)) {
        recent_data = (GtkRecentData *) g_new0(GtkRecentData, 1);
        if (artist != NULL && strlen(artist) > 0) {
            recent_data->display_name = g_strdup_printf("%s - %s", artist, title);
        } else {
            recent_data->display_name = g_strdup(title);
        }
        g_strlcpy(idledata->display_name, recent_data->display_name, 1024);


        file = g_file_new_for_uri(uri);
        file_info = g_file_query_info(file,
                                      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
                                      G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, NULL);


        if (file_info) {
            recent_data->mime_type = g_strdup(g_file_info_get_content_type(file_info));
            g_object_unref(file_info);
        }
        g_object_unref(file);
        recent_data->app_name = g_strdup("gnome-mplayer");
        recent_data->app_exec = g_strdup("gnome-mplayer %u");
        if (recent_data->mime_type != NULL) {
            gtk_recent_manager_add_full(recent_manager, uri, recent_data);
            g_free(recent_data->mime_type);
        }
        g_free(recent_data->app_name);
        g_free(recent_data->app_exec);
        g_free(recent_data);

    }
#endif
#endif
    g_free(title);
    g_free(artist);
    g_free(album);
    if (demuxer != NULL) {
        g_strlcpy(idledata->demuxer, demuxer, 64);
        g_free(demuxer);
    } else {
        g_strlcpy(idledata->demuxer, "", 64);
    }

    last_x = 0;
    last_y = 0;
    idledata->width = width;
    idledata->height = height;

    idledata->retry_on_full_cache = FALSE;
    idledata->cachepercent = -1.0;
    g_strlcpy(idledata->info, uri, 1024);
    set_media_info(idledata);

    streaming = 0;

    gm_store = gm_pref_store_new("gnome-mplayer");
    forcecache = gm_pref_store_get_boolean(gm_store, FORCECACHE);
    gm_pref_store_free(gm_store);


    if (g_ascii_strcasecmp(uri, "dvdnav://") == 0) {
        gtk_widget_show(menu_event_box);
    } else {
        gtk_widget_hide(menu_event_box);
    }

    if (autostart) {
        g_idle_add(hide_buttons, idledata);
        js_state = STATE_PLAYING;

        if (g_str_has_prefix(uri, "mmshttp") || g_str_has_prefix(uri, "http") || g_str_has_prefix(uri, "mms")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_NETWORK);
        } else if (g_str_has_prefix(uri, "dvd") || g_str_has_prefix(uri, "dvdnav")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVD);
        } else if (g_str_has_prefix(uri, "cdda")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_CD);
        } else if (g_str_has_prefix(uri, "cddb")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_CD);
        } else if (g_str_has_prefix(uri, "vcd")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_VCD);
        } else if (g_str_has_prefix(uri, "tv")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_TV);
        } else if (g_str_has_prefix(uri, "dvb")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVB);
        } else if (g_str_has_prefix(uri, "file")) {
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_FILE);
        } else {
            // if all else fails it must be a network type
            gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_NETWORK);
        }

        gmtk_media_player_set_attribute_boolean(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_PLAYLIST, playlist);
        gmtk_media_player_set_uri(GMTK_MEDIA_PLAYER(media), uri);
        gmtk_media_player_set_state(GMTK_MEDIA_PLAYER(media), MEDIA_STATE_PLAY);

    }

    return 0;
}
コード例 #18
0
ファイル: recents.c プロジェクト: gasparfm/recents
gboolean main_include_task(gpointer _options)
{
  GtkRecentManager *grm = gtk_recent_manager_get_default();
  GtkRecentData *data;
  GSList* iterator = NULL;
  recent_file_options_t* options = _options;
  unsigned added = 0;		/* Total files added */

  static gchar* groups[] = {
    NULL
  };
  
  for (iterator = options->fileNames; iterator; iterator = iterator->next) 
    {
      char* _fileName = (char*)iterator->data;
      if (!file_exists(_fileName))
	{
	  if (!options->quiet)
	    fprintf (stderr, "Error '%s' does not exist!\n", _fileName);
	  continue;
	}

      char* fileName = realpath(_fileName, NULL);
      if (fileName==NULL)
	{
	  if (!options->quiet)
	    fprintf (stderr, "Error getting '%s' path!\n", _fileName);
	  continue;
	}
      data = g_slice_new(GtkRecentData);
      data->display_name=g_strdup(fileName);
      data->description = NULL;
      data->mime_type=get_mime(fileName);
      data->app_name = (gchar*) g_get_application_name();
      data->app_exec = g_strdup("recents");
      data->groups = groups;
      data->is_private = FALSE;
      gchar *uri = g_filename_to_uri(fileName, NULL, NULL);
      if (gtk_recent_manager_add_full(grm, uri, data)) 
	{
	  if (!options->quiet)
	    printf("File '%s' added successfully\n", fileName);
	  ++added;
	}

      if (options->touchFile)
	{
	  struct utimbuf utb;
	  time_t now = time(NULL);
	  utb.actime = now;
	  utb.modtime = now;
	  if ( (utime (fileName, &utb)<0) && (!options->quiet) )
	    {
	      fprintf (stderr, "Could not touch '%s' (errno: %d, %s)\n", fileName, errno, strerror(errno));
	    }
	}
      free(fileName);
    }

  options->result = (added == g_slist_length(options->fileNames))?0:100;
  gtk_main_quit();
}