Example #1
0
File: gnac-ui.c Project: GNOME/gnac
static void
gnac_ui_init_unique(void)
{
#ifdef HAVE_LIBUNIQUE
  /* We only want a single instance of gnac to be running */
  app = unique_app_new_with_commands("org.gnome.Gnac", NULL,
      "add-files", UNIQUE_CMD_ADD,
      "debug"    , UNIQUE_CMD_DEBUG,
      "verbose"  , UNIQUE_CMD_VERBOSE,
      NULL);
  g_signal_connect(app, "message-received",
      G_CALLBACK(gnac_ui_message_received_cb), NULL);

  if (unique_app_is_running(app)) {
    libgnac_info(_("An instance of Gnac is already running"));

    UniqueResponse response;

    /* Give the focus to the running instance */
    response = unique_app_send_message(app, UNIQUE_ACTIVATE, NULL);

    /* Transmit the debug option */
    if (options.debug) {
      response = unique_app_send_message(app, UNIQUE_CMD_DEBUG, NULL);
      if (response != UNIQUE_RESPONSE_OK) {
        libgnac_warning(_("Failed to transmit the debug option"));
      }
    /* Transmit the verbose option */
    } else if (options.verbose) {
      response = unique_app_send_message(app, UNIQUE_CMD_VERBOSE, NULL);
      if (response != UNIQUE_RESPONSE_OK) {
        libgnac_warning(_("Failed to transmit the verbose option"));
      }
    }

    /* Transmit filenames */
    if (options.filenames) {
      UniqueMessageData *message = unique_message_data_new();
      gchar **uris = gnac_utils_get_filenames_from_cmd_line(options.filenames);
      g_strfreev(options.filenames);
      if (!unique_message_data_set_uris(message, uris)) {
        libgnac_warning(_("Failed to convert some uris"));
      }
      g_strfreev(uris);
      response = unique_app_send_message(app, UNIQUE_CMD_ADD, message);
      unique_message_data_free(message);
      if (response != UNIQUE_RESPONSE_OK) {
        libgnac_warning(_("Failed to transmit filenames"));
      } else {
        libgnac_info(_("Filenames transmitted to the running instance"));
      }
    }

    g_object_unref(app);

    gnac_exit(response == UNIQUE_RESPONSE_OK);
  }
#endif /* HAVE_LIBUNIQUE */
}
Example #2
0
File: main.c Project: lcp/bisho
int
main (int argc, char **argv)
{
  UniqueApp *app;
  GtkWidget *window;

  g_thread_init (NULL);

  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  gtk_init (&argc, &argv);

  /* TODO: use GOption to parse arguments */

  app = unique_app_new_with_commands ("com.intel.Bisho", NULL,
                                      "callback", COMMAND_CALLBACK,
                                      NULL);

  if (unique_app_is_running (app)) {
    UniqueResponse response;

    if (argc != 2) {
      response = unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
    } else {
      UniqueMessageData *msg;
      msg = unique_message_data_new ();
      unique_message_data_set_uris (msg, argv + 1);
      response = unique_app_send_message (app, COMMAND_CALLBACK, msg);
      unique_message_data_free (msg);
    }

    if (response == UNIQUE_RESPONSE_OK)
      goto done;
  }

  load_modules ();

  window = bisho_window_new ();

  unique_app_watch_window (app, GTK_WINDOW (window));

  g_signal_connect (app, "message-received", G_CALLBACK (unique_message_cb), window);

  g_signal_connect (window, "delete-event", gtk_main_quit, NULL);

  gtk_widget_show (window);

  gtk_main ();

 done:
  g_object_unref (app);

  return 0;
}
Example #3
0
static gint
luaH_unique_send_message(lua_State *L)
{
    if (!application)
        luaL_error(L, "unique app not setup");

    if (!unique_app_is_running(application))
        luaL_error(L, "no other instances running");

    const gchar *text = luaL_checkstring(L, 1);
    UniqueMessageData *data = unique_message_data_new();
    unique_message_data_set_text(data, text, -1);
    unique_app_send_message(application, 1, data);
    unique_message_data_free(data);
    return 0;
}
Example #4
0
void
unique_instance(int argc, char **args, UniqueApp *app)
{
	int	 i = 0;

	/* FIXME - rework. */
	for(; i < argc; ++i)
	{
		if (strcmp( args[i], "next-socket" ) == 0)
		{

			UniqueMessageData* data = unique_message_data_new();
			unique_message_data_set_text(data, args[i], strlen(args[i]));

			unique_app_send_message(app, COMMAND_PRINT_XID, data);
			unique_message_data_free(data);
		}
	}

	g_object_unref(app);
}
Example #5
0
void
totem_options_process_for_server (UniqueApp *app,
				  const TotemCmdLineOptions* options)
{
	GList *commands, *l;
	int default_action, i;

	commands = NULL;
	default_action = TOTEM_REMOTE_COMMAND_REPLACE;

	/* Are we quitting ? */
	if (options->quit) {
		unique_app_send_message (app, TOTEM_REMOTE_COMMAND_QUIT, NULL);
		return;
	}

	/* Then handle the things that modify the playlist */
	if (options->replace && options->enqueue) {
		/* FIXME translate that */
		g_warning ("Can't enqueue and replace at the same time");
	} else if (options->replace) {
		default_action = TOTEM_REMOTE_COMMAND_REPLACE;
	} else if (options->enqueue) {
		default_action = TOTEM_REMOTE_COMMAND_ENQUEUE;
	}

	/* Send the files to enqueue */
	for (i = 0; options->filenames && options->filenames[i] != NULL; i++) {
		UniqueMessageData *data;
		char *full_path;

		data = unique_message_data_new ();
		full_path = totem_create_full_path (options->filenames[i]);
		unique_message_data_set_text (data, full_path ? full_path : options->filenames[i], -1);
		full_path = totem_create_full_path (options->filenames[i]);

		unique_app_send_message (app, default_action, data);

		/* Even if the default action is replace, we only want to replace with the
		   first file.  After that, we enqueue. */
		default_action = TOTEM_REMOTE_COMMAND_ENQUEUE;
		unique_message_data_free (data);
		g_free (full_path);
	}

	if (options->playpause) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_PLAYPAUSE));
	}

	if (options->play) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_PLAY));
	}

	if (options->pause) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_PAUSE));
	}

	if (options->next) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_NEXT));
	}

	if (options->previous) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_PREVIOUS));
	}

	if (options->seekfwd) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_SEEK_FORWARD));
	}

	if (options->seekbwd) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_SEEK_BACKWARD));
	}

	if (options->volumeup) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_VOLUME_UP));
	}

	if (options->volumedown) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_VOLUME_DOWN));
	}

	if (options->mute) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_MUTE));
	}

	if (options->fullscreen) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_FULLSCREEN));
	}

	if (options->togglecontrols) {
		commands = g_list_append (commands, GINT_TO_POINTER
					  (TOTEM_REMOTE_COMMAND_TOGGLE_CONTROLS));
	}

	/* No commands, no files, show ourselves */
	if (commands == NULL && options->filenames == NULL) {
		unique_app_send_message (app, TOTEM_REMOTE_COMMAND_SHOW, NULL);
		return;
	}

	/* Send commands */
	for (l = commands; l != NULL; l = l->next) {
		int command = GPOINTER_TO_INT (l->data);
		unique_app_send_message (app, command, NULL);
	}
	g_list_free (commands);
}
Example #6
0
int start( int argc, char **argv )
{
  char file[PATH_MAX];
  char *f = NULL;
  char line[7];
  int lineToOpen = 0;

  memset(file,'\0',PATH_MAX);
  memset(line,'\0',7);

  gtk_init( &argc, &argv );

  //printf("arguments::\n");

  for( int i = 0; i < argc; i++ )
  {
    //printf(" argument %d is %s\n",i,argv[i]);fflush(stdout);
    if( i == 1 )
    {
      strncpy(file,argv[i],PATH_MAX);
      f = fileFullPath(file);
    }
    else if( i == 2 )
    {
      strncpy(line,argv[i],6);
      lineToOpen = atoi(line);
      if( lineToOpen < 0 ) lineToOpen = 0;
    }
  }

  g_app = unique_app_new(EDITOR,NULL);

  if( unique_app_is_running (g_app) )
  {
    char* fl = NULL;
    int len = 0;
    UniqueCommand cmd = UNIQUE_NEW;
    UniqueMessageData* msg = unique_message_data_new();

    if( f ) len += strlen(f);
    if( lineToOpen ) len += strlen(line) + 1;
    fl = (char*)malloc(len+1);
    
    if( f )
    {
      strcpy(fl,f);
      free(f);
      
      if( lineToOpen )
      {
        strcat(fl,"@");
        strcat(fl,line);
      }
    }

    if( len > 1 && fl )
    {      
      cmd = UNIQUE_OPEN;
      unique_message_data_set_text(msg,fl,len);
      free(fl);
    }
    
    unique_app_send_message(g_app,cmd,msg);
    unique_message_data_free(msg);
  }
  else
  {
    if(f) free(f);
    //g_appWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    //unique_app_watch_window (app, GTK_WINDOW(g_appWin));
    g_signal_connect(g_app,"message-received",G_CALLBACK(message_received_cb),NULL);

    MyEditorHandlerLin* meh = (MyEditorHandlerLin*)MyEditorHandlerLin::getInstance();
    meh->createEditor(file,lineToOpen);

    gtk_main();

    //gtk_widget_destroy(g_appWin);
  }

  g_object_unref (g_app);

  return 0;
}