Beispiel #1
0
void bmark_add(Tbfwin * bfwin) {
	GtkTextMark *im;
	GtkTextIter it;
	gint offset;
	/* check for unnamed document */
	if (!DOCUMENT(bfwin->current_document)->filename) {
		error_dialog(bfwin->main_window, _("Add bookmark"),
					 _("Cannot add bookmarks in unnamed files."));
					 /*\nPlease save the file first. A Save button in this dialog would be cool -- Alastair*/
		return;
	}
	/* if the left panel is disabled, we simply should add the bookmark to the list, and do nothing else */
/*	if (bfwin->bmark == NULL) {
		DEBUG_MSG("no left panel, this is not implemented yet\n");
	} else */ {
		gboolean has_mark;
		im = gtk_text_buffer_get_insert(DOCUMENT(bfwin->current_document)->buffer);
		gtk_text_buffer_get_iter_at_mark(DOCUMENT(bfwin->current_document)->buffer, &it, im);
		offset = gtk_text_iter_get_offset(&it);
	
		/* check for existing bookmark in this place */
		has_mark = (bmark_get_bmark_at_line(DOCUMENT(bfwin->current_document), offset) != NULL);
		if (has_mark) {
			info_dialog(bfwin->main_window, _("Add bookmark"),
						_("You already have a bookmark here!"));
			{/* delete bookmark stuff */
			}
			return;
		}
		bmark_add_current_doc_backend(bfwin, "", offset, !main_v->props.bookmarks_default_store);
	}
}
Beispiel #2
0
static void export_gpx_button_clicked(GtkWidget *widget, gpointer data)
{
	GtkTreeIter iter;
	char *file = get_selected_file(&iter);
	if (file) {
		export_gpx(file);
	} else {
		info_dialog("Export .gpx file: no file selected!");
	}
}
Beispiel #3
0
static void view_button_clicked(GtkWidget *widget, gpointer data)
{
	char buf[256];

	if (! selected_file) {
		info_dialog("no file was selected!");
		return;
	}
	get_full_path(buf, sizeof(buf), selected_file);

	gtk_image_set_from_file(GTK_IMAGE(screenshot_image), buf);
	gtk_label_set_text(GTK_LABEL(screenshot_label), buf);
	gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
}
Beispiel #4
0
static void replay_button_clicked(GtkWidget *widget, gpointer data)
{
	GtkTreeIter iter;
	char *file = get_selected_file(&iter);
	if (file) {
		if (replay_file_path)
			free(replay_file_path);

		replay_file = file;
		replay_file_path = get_full_path(NULL, 256, file);

		switch_to_main_view(CTX_ID_TRACK_REPLAY);
	} else {
		info_dialog("Replay: no file selected!");
	}
}
Beispiel #5
0
static void delete_button_clicked(GtkWidget *widget, gpointer data)
{
	GtkTreeIter iter;
	char *file = get_selected_file(&iter);
	if (file) {
		char buf[64];
		snprintf(buf, sizeof(buf), "Delete file:\n\n%s", file);
		if (confirm_dialog(buf)) {
			gtk_list_store_remove (filelist_store, &iter);
			char buf[256];
			char *path = get_full_path(buf, sizeof(buf), file);
			unlink(path);
		}
	} else {
		info_dialog("Delete: no file selected!");
	}
}
Beispiel #6
0
static void delete_button_clicked(GtkWidget *widget, gpointer data)
{
	char buf[256];

	if (! selected_file) {
		info_dialog("no file was selected!");
		return;
	}

	snprintf(buf, sizeof(buf), "Delete file:\n\n%s", selected_file);

	if (confirm_dialog(buf)) {
		gtk_list_store_remove (filelist_store, &selected_iter);
		get_full_path(buf, sizeof(buf), selected_file);
		unlink(buf);

		gtk_widget_set_sensitive(view_button, FALSE);
		gtk_widget_set_sensitive(delete_button, FALSE);
	}
}
Beispiel #7
0
void do_screenshot()
{
	#define SS_PREFIX "Save screenshot: "
	struct stat st;
	char buf[256];

	int i = 1;
	do {
		snprintf(buf, sizeof(buf), "%s/%04d%s", g_context.screenshot_dir, i++, SCREENSHOT_FILE_EXT);
	} while (stat(buf, &st) == 0);

	GError *err = NULL;

	GdkPixbuf *pixbuf = gdk_pixbuf_get_from_drawable(NULL, g_view.da->window, NULL,
		g_view.fglayer.visible.x, g_view.fglayer.visible.y, 0, 0,
		g_view.fglayer.visible.width, g_view.fglayer.visible.height);

	if (pixbuf == NULL) {
		warn_dialog(SS_PREFIX"unable to capture from window");
		return;
	}

	gboolean ret = gdk_pixbuf_save (pixbuf, buf, SCREENSHOT_FILE_TYPE, &err, "tEXt::Software", "omgps", NULL);
	gdk_pixbuf_unref(pixbuf);

	if (ret) {
		char buf1[128];
		snprintf(buf1, sizeof(buf1), SS_PREFIX"saved as: %s", buf);

		GtkTreeIter iter;
		gtk_list_store_insert (filelist_store, &iter, 0);
		add_file_to_list(&iter, buf, &buf[strlen(g_context.screenshot_dir) + 1]);
		info_dialog(buf1);
	} else {
		snprintf(buf, sizeof(buf), SS_PREFIX"unable to save, error=%s", err->message);
		g_error_free (err);
		warn_dialog(buf);
	}
}
Beispiel #8
0
void input_update() {
	SDL_Event event;

	while(SDL_PollEvent(&event)) {
		if(r_menu) {
			switch(event.type) {
				case SDL_QUIT: Game::run=false; break;

				case SDL_KEYDOWN:
					switch(event.key.keysym.sym) {
						case SDLK_w:	if(menu_choice) --menu_choice; else menu_choice=6;		break;

						case SDLK_s:	if(menu_choice<6) ++menu_choice; else menu_choice=0;	break;

						case SDLK_e:
							switch(menu_choice) {
                                                                case 1:
                                                                        r_menu=false;
                                                                        r_pokemenu=true;
                                                                        menu_text = "Select a pokemon.";
                                                                        info_dialog(menu_text);
								        soundevents.push_back(new Sound(soundbuffers[0]));
							        	soundevents.back()->play();
                                                                        break;
								case 4:
									savegame();
									soundevents.push_back(new Sound(soundbuffers[0]));
									soundevents.back()->play();
									r_menu=false;
								break;
								case 6: Game::run=false; break;
							}
						break;

						case SDLK_SPACE:	r_menu=false;		break;
						default:break;
					}
			}
		}
                else if(r_pokemenu)
                {
			switch(event.type) {
				case SDL_QUIT: Game::run=false; break;

				case SDL_KEYDOWN:
					switch(event.key.keysym.sym) {
						case SDLK_w:	if(poke_choice) --poke_choice; else poke_choice=5;		break;

						case SDLK_s:	if(poke_choice<5) ++poke_choice; else poke_choice=0;	break;

						case SDLK_e:
							switch(menu_choice) {
                                                          // POKEMON NOT IMPLEMENTED YET!
                                                          default:
                                                                  break;
							}
						break;

						case SDLK_SPACE:
                                                        r_pokemenu=false;
                                                        r_menu = true;
                                                        menu_text = "";
                                                        info_dialog(menu_text);
                                                        break;
						default:break;
					}
			}
                }
		else {
			switch(event.type) {
				case SDL_QUIT: Game::run=false; break;

				case SDL_KEYDOWN:
					switch(event.key.keysym.sym) {
						case SDLK_a:		if(!player.talking) player.start(4);	break;

						case SDLK_w:		if(!player.talking) player.start(8);	break;

						case SDLK_s:		if(!player.talking) player.start(16);	break;

						case SDLK_d:		if(!player.talking) player.start(2);	break;

						case SDLK_e:		KEY_E_DOWN=true;	break;

						case SDLK_SPACE:
							if(!player.talking) {
								player.stop();
								r_menu=true;
								soundevents.push_back(new Sound(soundbuffers[0]));
								soundevents.back()->play();
							}
						break;
						default: break;
					}
				break;

				case SDL_KEYUP:
					switch(event.key.keysym.sym) {
						case SDLK_a:		if(player.direction()==4) player.stop();	break;

						case SDLK_w:		if(player.direction()==8) player.stop();	break;

						case SDLK_s:		if(player.direction()==16) player.stop();	break;

						case SDLK_d:		if(player.direction()==2) player.stop();	break;

						case SDLK_e:		KEY_E_DOWN=false;							break;
						default: break;
					}
				break;
			}
		}
	}
}
Beispiel #9
0
void
PrefAgent::get_geometry (WCallback *wcb)
{
  WXmTextField text_field ((Widget)wcb->ClientData());
  char *shell_name = NULL;
  if (text_field == f_map_geo)
    shell_name = (char*)"map";
  else if (text_field == f_browse_geo)
    shell_name = (char*)"nodeview";
    
  // Display an instructional dialog. 
  WXmMessageDialog
    info_dialog ((Widget)f_shell, (char*)"geometry_msg",
		 WArgList (XmNdialogType, XmDIALOG_INFORMATION, NULL));
  WXmDialogShell shell (info_dialog.Parent());
  // set window title
  String string = CATGETS(Set_PrefAgent, 2, "Dtinfo: Get Geometry");
  XtVaSetValues((Widget)shell, XmNtitle, string, NULL);
  //  window_system().register_full_modal_shell (&shell);
  info_dialog.MessageString (
	(char*)UAS_String(CATGETS(Set_Messages, 16, "File a Bug")));
  XtUnmanageChild (info_dialog.OkPB());
  XtUnmanageChild (info_dialog.HelpPB());

  XtVaSetValues((Widget)info_dialog, XmNdefaultPosition, False, NULL);

  // Wait for the dialog to appear. 
  int mapped = FALSE;
  info_dialog.Manage();
  XtAddEventHandler (info_dialog, ExposureMask, False,
		     dialog_mapped, (XtPointer) &mapped);
  XtAppContext app_context = window_system().app_context();
  XEvent event;
  while (!mapped)
    {
      XtAppNextEvent (app_context, &event);
      XtDispatchEvent (&event);
    }

  // Let the user pick an OLIAS window. 
  static Cursor pick_cursor =
    XCreateFontCursor (window_system().display(), XC_crosshair);
  Widget target;
  target = XmTrackingEvent (f_shell, pick_cursor, False, &event);

  // Get the geometry of the selected window.
  while (target != NULL && !XtIsShell (target))
    target = XtParent (target);

  if (target != (Widget) info_dialog.Parent())
    {
      // Make sure the user clicked on the right kind of window.
      if (target != NULL && strcmp (XtName(target), shell_name) != 0)
	target = NULL;

      if (target == NULL)
	{
	  XBell (window_system().display(), 100);
	}
      else
	{
	  WShell shell (target);
	  WindowGeometry wg;
	  wg.width = shell.Width();
	  wg.height = shell.Height();
	  set_geometry (text_field, wg);
	}
    }

  // Nuke the dialog.
  info_dialog.Unmanage();
  XtDestroyWidget (info_dialog.Parent());
}
Beispiel #10
0
/**
 * <topleft> and <botright>: tile pixel
 */
static void tile_batch_download(int levels, coord_t tl_wgs84, coord_t br_wgs84)
{
	map_repo_t *repo = g_view.fglayer.repo;
	int zoom = repo->zoom;

	if (zoom + levels > repo->max_zoom)
		levels = repo->max_zoom - zoom;

	batch_dl_t *batch = (batch_dl_t*)malloc(sizeof(batch_dl_t));
	if (! batch) {
		warn_dialog("batch download:\n\nunable to allocate memory!");
		return;
	}

	batch->repo = repo;
	batch->min_zoom = zoom + 1;
	batch->max_zoom = zoom + levels;
	batch->tl_wgs84 = tl_wgs84;
	batch->br_wgs84 = br_wgs84;

	/* prepare */

	int exists_size = batch_download_prepare(batch);

	if (exists_size < 0) {
		warn_dialog("batch download:\nallocate memory failed!");
		return;
	}
	float size_est;

	/* MB */
	if (batch->num_in_range == batch->num_dl_total)
		size_est = batch->num_dl_total * 0.01; // estimate
	else {
		int average_size = exists_size / (batch->num_in_range - batch->num_dl_total);
		size_est = 1.0 * average_size * batch->num_dl_total / (1024 * 1024);
	}

	char buf[128];
	if (batch->num_dl_total == 0) {
		snprintf(buf, sizeof(buf), "total %d tiles, already on disk.", batch->num_in_range);
		info_dialog(buf);
		return;
	}

	/* Assume each download takes 1 second */
	int seconds = (int)ceil((1 + 1000.0 / DL_SLEEP_MS) * batch->num_dl_total / TILE_DL_THREADS_LIMIT);
	int h = seconds / 3600;
	int remains = seconds - h * 3600;
	int m = remains / 60;
	int s = remains - m * 60;

	snprintf(buf, sizeof(buf), "tiles: %d of %d, disk space: ~%.2fMB, time: > %d:%d:%d",
		batch->num_dl_total, batch->num_in_range, size_est, h, m, s);

	if (! confirm_dialog(buf)) {
		free(batch);
		return;
	}

	/* batch download */

	log_info("batch download: map=%s, zoom=%d, +levels=%d", repo->name, zoom, levels);
	log_info("%s", buf);

	batch_download(batch);
}
Beispiel #11
0
static void export_gpx(char *file)
{
	char fullpath[256];
	FILE *fp_src = NULL, *fp_dest = NULL;

	get_full_path(fullpath, sizeof(fullpath), file);

	fp_src = fopen(fullpath, "r");
	if (! fp_src) {
		warn_dialog("Unable to open src file");
		return;
	}

	/* NOTE: now fullpath refers to dest file */
	sprintf(fullpath + strlen(fullpath) - 4, "%s", ".gpx");

	fp_dest = fopen(fullpath, "w+");
	if (! fp_dest) {
		warn_dialog("Unable to open dest file");
		fclose(fp_src);
		return;
	}

	gboolean ret = TRUE;

	/* head */
	U4 start_time, end_time, record_count;
	fscanf(fp_src, TRACK_HEAD_LABEL_1"%u\n", &start_time);
	fscanf(fp_src, TRACK_HEAD_LABEL_2"%u\n", &end_time);
	fscanf(fp_src, TRACK_HEAD_LABEL_3"%u\n", &record_count);

	double lat, lon;
	U4 time_offset;
	int n;

	char tm_buf[64];
	time_t tt = start_time;
	struct tm *tm = gmtime(&tt);

	fprintf(fp_dest,
		"<?xml version=\"1.0\"?>\n<gpx version=\"1.1\" creator=\"omgps - http://code.google.com/p/omgps/\"\n "
		"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n "
		"xmlns=\"http://www.topografix.com/GPX/1/1\"\n"
		"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n");

	strftime(tm_buf, sizeof(tm_buf), "%Y-%m-%dT%H:%M:%SZ", tm);
	fprintf(fp_dest, "<time>%s</time>\n", tm_buf);
	fprintf(fp_dest, "<trk>\n");

	strftime(tm_buf, sizeof(tm_buf), "%Y%m%d_%H%M%S", tm);
	fprintf(fp_dest, "<name>omgps--%s", tm_buf);
	tt = end_time;
	tm = gmtime(&tt);
	strftime(tm_buf, sizeof(tm_buf), "%Y%m%d_%H%M%S", tm);
	fprintf(fp_dest, "-%s</name>\n", tm_buf);
	fprintf(fp_dest, "<trkseg>\n");

	while (TRUE) {
		n = fscanf(fp_src, "%lf\t%lf\t%u\n", &lat, &lon, &time_offset);
		if (n == EOF)
			break;
		else if (n != 3) {
			warn_dialog("Read src file failed");
			ret = FALSE;
			goto END;
		}
		tt = start_time + time_offset;
		tm = gmtime(&tt);
		strftime(tm_buf, sizeof(tm_buf), "%Y-%m-%dT%H:%M:%SZ", tm);
		fprintf(fp_dest, "<trkpt lat=\"%f\" lon=\"%f\"><time>%s</time></trkpt>\n",
				lat, lon, tm_buf);
	}
	fprintf(fp_dest, "</trkseg>\n</trk>\n</gpx>\n");

END:

	if (fp_src)
		fclose(fp_src);

	if (fp_dest)
		fclose(fp_dest);

	if (! ret)
		unlink(fullpath);
	else {
		char buf[256];
		snprintf(buf, sizeof(buf), "The .gpx file was exported as: %s", fullpath);
		info_dialog(buf);
	}
}
Beispiel #12
0
void plugin_exec(gint plugin_num)
{
	Plugin *plugin;
	gchar *stdout = NULL;
	GError *error = NULL;
	gint exit_status;
	GString *command_line = NULL;
	gint wordStart;
	gint wordEnd;
	gchar *current_selection;
	gint ac_length;
	gchar *data;
	
	if (main_window.current_editor == NULL) {
		return;
	}
	
	plugin = (Plugin *)g_list_nth_data(Plugins, plugin_num);
	if (!plugin) {
		g_print(_("Plugin is null!\n"));
	}
	//g_print("Plugin No: %d:%d (%s):%s\n", plugin_num, plugin->type, plugin->name, plugin->filename->str);
	command_line = g_string_new(plugin->filename->str);
	command_line = g_string_prepend(command_line, "'");
	command_line = g_string_append(command_line, "' '");
	
	if (plugin->type == GPHPEDIT_PLUGIN_TYPE_SELECTION) {
		wordStart = gtk_scintilla_get_selection_start(GTK_SCINTILLA(main_window.current_editor->scintilla));
		wordEnd = gtk_scintilla_get_selection_end(GTK_SCINTILLA(main_window.current_editor->scintilla));
		current_selection = gtk_scintilla_get_text_range (GTK_SCINTILLA(main_window.current_editor->scintilla), wordStart, wordEnd, &ac_length);
		
		command_line = g_string_append(command_line, current_selection);
	}
	else if (plugin->type == GPHPEDIT_PLUGIN_TYPE_FILENAME) {
		command_line = g_string_append(command_line, editor_convert_to_local(main_window.current_editor));		
	}
	command_line = g_string_append(command_line, "'");
	
	//g_print("SPAWNING: %s\n", command_line->str);
	
	if (g_spawn_command_line_sync(command_line->str,&stdout,NULL, &exit_status,&error)) {
		data = strstr(stdout, "\n");
		data++;
		
		//g_print("COMMAND: %s\nSTDOUT:%s\nOUTPUT: %s\n", command_line->str, stdout, data);
		
		if (g_strncasecmp(stdout, "INSERT", MIN(strlen(stdout), 6))==0) {
			if (data) {
				gtk_scintilla_insert_text(GTK_SCINTILLA(main_window.current_editor->scintilla), 
					gtk_scintilla_get_current_pos(GTK_SCINTILLA(main_window.current_editor->scintilla)), data);
			}
		}
		else if (g_strncasecmp(stdout, "REPLACE", MIN(strlen(stdout), 7))==0) {
			if (data) {
				gtk_scintilla_replace_sel(GTK_SCINTILLA(main_window.current_editor->scintilla), data);
			}
		}
		else if (g_strncasecmp(stdout, "MESSAGE", MIN(strlen(stdout),7))==0) {
				info_dialog(plugin->name, data);
		}
		else if (g_strncasecmp(stdout, "OPEN", MIN(strlen(stdout), 4))==0) {
			if (DEBUG_MODE) { g_print("DEBUG: main_window.c:plugin_exec: Opening file :date: %s\n", data); }
			switch_to_file_or_open(data, 0);
		}
		else if (g_strncasecmp(stdout, "DEBUG", MIN(strlen(stdout), 5))==0) {
			debug_dump_editors();
			DEBUG_MODE = TRUE;
		}
		
		g_free(stdout);

	}
	else {
		g_print(_("Spawning %s gave error %s\n"), plugin->filename->str, error->message);
	}
}