"Fossies" - the Fresh Open Source Software Archive

Member "xzgv-0.9.2/src/gotodir.c" (3 Sep 2017, 4431 Bytes) of package /linux/misc/old/xzgv-0.9.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gotodir.c" see the Fossies "Dox" file reference documentation.

    1 /* xzgv v0.2 - picture viewer for X, with file selector.
    2  * Copyright (C) 1999 Russell Marks. See main.c for license details.
    3  *
    4  * gotodir.c - `go to dir' dialog.
    5  */
    6 
    7 #include <stdio.h>
    8 #include <string.h>
    9 #include <stdlib.h>
   10 #include <unistd.h>
   11 #include <sys/types.h>
   12 #include <sys/stat.h>
   13 #include <gtk/gtk.h>
   14 #include <gdk/gdkkeysyms.h>
   15 #include "backend.h"
   16 #include "main.h"
   17 
   18 #include "gotodir.h"
   19 
   20 
   21 static GtkWidget *dir_win;
   22 
   23 
   24 
   25 static void cb_ok_button(GtkWidget *button,GtkWidget *entry)
   26 {
   27 const char *ptr=gtk_entry_get_text(GTK_ENTRY(entry));
   28 int ret;
   29 
   30 if(!ptr || *ptr==0 || strcmp(ptr,".")==0)
   31   {
   32   gtk_widget_destroy(dir_win);
   33   return;
   34   }
   35 
   36 if(*ptr=='~' && getenv("HOME"))     /* kludge for home dir */
   37   ptr=g_strdup_printf("%s%s",getenv("HOME"),ptr+1);
   38 else
   39   ptr=g_strdup(ptr);    /* not needed but easier this way :-) */
   40 
   41 ret=chdir(ptr);
   42 
   43 free((void *)ptr);
   44 gtk_widget_destroy(dir_win);
   45 
   46 if(ret==0)
   47   {
   48   stop_thumbnail_read();
   49   do_gtk_stuff(); /* sometimes there's a delay before redraw otherwise */
   50   reinit_dir(1,0);
   51   }
   52 else
   53   error_dialog("xzgv error","Couldn't change directory!");
   54 }
   55 
   56 
   57 void cb_goto_dir(void)
   58 {
   59 GtkWidget *vbox;
   60 GtkWidget *action_tbl,*ok_button,*cancel_button;
   61 GtkWidget *table;
   62 GtkWidget *label,*entry;
   63 static char cdir[1024],buf[1024];
   64 int tbl_row;
   65 
   66 getcwd(cdir,sizeof(cdir)-1);
   67 
   68 dir_win=gtk_dialog_new();
   69 
   70 gtk_window_set_title(GTK_WINDOW(dir_win),"Go to directory");
   71 gtk_window_set_policy(GTK_WINDOW(dir_win),FALSE,TRUE,FALSE);
   72 gtk_window_set_position(GTK_WINDOW(dir_win),GTK_WIN_POS_CENTER);
   73 /* seems reasonable to have this as modal */
   74 gtk_window_set_modal(GTK_WINDOW(dir_win),TRUE);
   75 
   76 /* make a new vbox for the top part so we can get spacing more sane */
   77 vbox=gtk_vbox_new(FALSE,10);
   78 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dir_win)->vbox),
   79                    vbox,TRUE,TRUE,0);
   80 gtk_widget_show(vbox);
   81 
   82 gtk_container_set_border_width(GTK_CONTAINER(vbox),5);
   83 gtk_container_set_border_width(
   84   GTK_CONTAINER(GTK_DIALOG(dir_win)->action_area),5);
   85 
   86 /* add ok/cancel buttons */
   87 action_tbl=gtk_table_new(1,5,TRUE);
   88 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dir_win)->action_area),
   89                    action_tbl,TRUE,TRUE,0);
   90 gtk_widget_show(action_tbl);
   91 
   92 ok_button=gtk_button_new_with_label("Ok");
   93 gtk_table_attach_defaults(GTK_TABLE(action_tbl),ok_button, 1,2, 0,1);
   94 /* we connect the signal later, so we can refer to the text-entry */
   95 gtk_widget_show(ok_button);
   96 
   97 cancel_button=gtk_button_new_with_label("Cancel");
   98 gtk_table_attach_defaults(GTK_TABLE(action_tbl),cancel_button, 3,4, 0,1);
   99 gtk_signal_connect_object(GTK_OBJECT(cancel_button),"clicked",
  100                           GTK_SIGNAL_FUNC(gtk_widget_destroy),GTK_OBJECT(dir_win));
  101 gtk_widget_show(cancel_button);
  102 
  103 
  104 table=gtk_table_new(2,3,TRUE);
  105 gtk_box_pack_start(GTK_BOX(vbox),table,TRUE,TRUE,0);
  106 gtk_table_set_col_spacings(GTK_TABLE(table),20);
  107 gtk_table_set_row_spacings(GTK_TABLE(table),8);
  108 gtk_container_set_border_width(GTK_CONTAINER(table),8);
  109 gtk_widget_show(table);
  110 
  111 #define DO_TBL_LEFT(table,row,name) \
  112   label=gtk_label_new(name);                \
  113   gtk_misc_set_alignment(GTK_MISC(label),1.,0.5);   \
  114   gtk_table_attach_defaults(GTK_TABLE(table),label, 0,1, (row),(row)+1); \
  115   gtk_widget_show(label)
  116 
  117 #define DO_TBL_RIGHT(table,row,name) \
  118   label=gtk_label_new(name);                \
  119   gtk_misc_set_alignment(GTK_MISC(label),0.,0.5);   \
  120   gtk_table_attach_defaults(GTK_TABLE(table),label, 1,3, (row),(row)+1); \
  121   gtk_widget_show(label)
  122 
  123 tbl_row=0;
  124 
  125 DO_TBL_LEFT(table,tbl_row,"Current dir:");
  126 DO_TBL_RIGHT(table,tbl_row,cdir);
  127 tbl_row++;
  128 
  129 DO_TBL_LEFT(table,tbl_row,"New dir:");
  130 
  131 entry=gtk_entry_new_with_max_length(sizeof(buf)-1);
  132 gtk_table_attach_defaults(GTK_TABLE(table),entry, 1,3, tbl_row,tbl_row+1);
  133 gtk_widget_grab_focus(entry);
  134 gtk_widget_show(entry);
  135 gtk_signal_connect(GTK_OBJECT(entry),"activate",
  136                    GTK_SIGNAL_FUNC(cb_ok_button),GTK_OBJECT(entry));
  137 
  138 /* finally connect up the ok button */
  139 gtk_signal_connect(GTK_OBJECT(ok_button),"clicked",
  140                    GTK_SIGNAL_FUNC(cb_ok_button),GTK_OBJECT(entry));
  141 
  142 
  143 /* esc = cancel */
  144 gtk_widget_add_accelerator(cancel_button,"clicked",
  145                            mainwin_accel_group,
  146                            GDK_Escape,0,0);
  147 
  148 gtk_widget_add_accelerator(ok_button,"clicked",
  149                            mainwin_accel_group,
  150                            GDK_Return,0,0);
  151 
  152 
  153 gtk_widget_show(dir_win);
  154 
  155 /* that's it then; it's modal so we can just leave GTK+ to deal with things. */
  156 }