/[xlog]/xlog/src/utils.c
ViewVC logotype

Diff of /xlog/src/utils.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by pa4tu, Thu Nov 21 19:52:39 2002 UTC revision 1.4 by pa4tu, Thu Nov 21 19:57:46 2002 UTC
# Line 66  extern GList *logwindowlist; Line 66  extern GList *logwindowlist;
66  extern GdkColormap *colormap;  extern GdkColormap *colormap;
67    
68  #if WANT_HAMLIB  #if WANT_HAMLIB
69          extern gint hamlibtimer;  extern gint hamlibtimer;
70          extern RIG *myrig;  extern RIG *myrig;
71          extern GList *riglist;  extern GList *riglist;
72  #endif  #endif
73    
74    
75  /* calculate location string from latitude and longitude information,  /* calculate location string from latitude and longitude information,
76   * returned value has to be freed */   * returned value has to be freed */
77  gchar *setlocation(gdouble lat, gint NS, gdouble lon, gint EW)  gchar *
78    setlocation (gdouble lat, gint NS, gdouble lon, gint EW)
79  {  {
80          gchar *location, *ns, *ew;    gchar *location, *ns, *ew;
81    
82          if (NS == 1) ns = g_strdup(_("N")); else ns = g_strdup(_("S"));    if (NS == 1)
83          if (EW == 1) ew = g_strdup(_("E")); else ew = g_strdup(_("W"));      ns = g_strdup (_("N"));
84          location = g_strdup_printf("%3.2f%s%3.2f%s", lat, ns, lon, ew);    else
85          g_free(ns);      ns = g_strdup (_("S"));
86          g_free(ew);    if (EW == 1)
87        ew = g_strdup (_("E"));
88      else
89        ew = g_strdup (_("W"));
90      location = g_strdup_printf ("%3.2f%s%3.2f%s", lat, ns, lon, ew);
91      g_free (ns);
92      g_free (ew);
93    
94          return(location);    return (location);
95  }  }
96    
97  /* update the menu items of an optionmenu */  /* update the menu items of an optionmenu */
98  void updateoptionmenu(GtkWidget *optionmenu, gchar **split)  void
99    updateoptionmenu (GtkWidget * optionmenu, gchar ** split)
100  {  {
101          GtkWidget *menu, *menuitem;    GtkWidget *menu, *menuitem;
102          gint index = 0;    gint index = 0;
103            
104          menu = gtk_menu_new();    menu = gtk_menu_new ();
105          for (;;)    for (;;)
106          {      {
107                  if (split[index] == NULL) break;        if (split[index] == NULL)
108                  menuitem = gtk_menu_item_new_with_label(split[index]);          break;
109                  gtk_widget_show(menuitem);        menuitem = gtk_menu_item_new_with_label (split[index]);
110                  gtk_menu_append(GTK_MENU(menu), menuitem);        gtk_widget_show (menuitem);
111                  index++;        gtk_menu_append (GTK_MENU (menu), menuitem);
112          }        index++;
113          gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu), menu);      }
114      gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
115  }  }
116    
117  /* removing leading and trailing whitespaces from an array of strings */  /* removing leading and trailing whitespaces from an array of strings */
118  void deletespaces(gchar **split)  void
119    deletespaces (gchar ** split)
120  {  {
121          gint index = 0;    gint index = 0;
122    
123          for (;;)    for (;;)
124          {      {
125                  if (split[index] == NULL) break;        if (split[index] == NULL)
126                  g_strstrip(split[index]);          break;
127                  index++;        g_strstrip (split[index]);
128          }        index++;
129        }
130  }  }
131    
132  /* clear statusbar */  /* clear statusbar */
133  static gint statusbar_timeout(gpointer data)  static gint
134    statusbar_timeout (gpointer data)
135  {  {
136          GtkWidget *statusbar;    GtkWidget *statusbar;
137    
138          statusbar = lookup_widget(mainwindow, "statusbar");    statusbar = lookup_widget (mainwindow, "statusbar");
139          gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 1);    gtk_statusbar_pop (GTK_STATUSBAR (statusbar), 1);
140          gtk_statusbar_push(GTK_STATUSBAR(statusbar), 1, _("Ready."));    gtk_statusbar_push (GTK_STATUSBAR (statusbar), 1, _("Ready."));
141          gtk_timeout_remove(statusbartimer);    gtk_timeout_remove (statusbartimer);
142          state.statustimer = FALSE;    state.statustimer = FALSE;
143          return FALSE;    return FALSE;
144  }  }
145    
146  /* change the statusbar */  /* change the statusbar */
147  void update_statusbar(gchar *string)  void
148    update_statusbar (gchar * string)
149  {  {
150          GtkWidget *statusbar;    GtkWidget *statusbar;
151    
152          statusbar = lookup_widget(mainwindow, "statusbar");    statusbar = lookup_widget (mainwindow, "statusbar");
153          gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 1);    gtk_statusbar_pop (GTK_STATUSBAR (statusbar), 1);
154          gtk_statusbar_push(GTK_STATUSBAR(statusbar), 1, string);    gtk_statusbar_push (GTK_STATUSBAR (statusbar), 1, string);
155          if (state.statustimer) gtk_timeout_remove(statusbartimer);    if (state.statustimer)
156          statusbartimer = gtk_timeout_add(30000, statusbar_timeout, NULL);      gtk_timeout_remove (statusbartimer);
157          state.statustimer = TRUE;    statusbartimer = gtk_timeout_add (30000, statusbar_timeout, NULL);
158      state.statustimer = TRUE;
159  }  }
160    
161  /* Needed by g_hash_table_foreach_remove, to free every key in the hash table */  /* Needed by g_hash_table_foreach_remove, to free every key in the hash table */
162  gboolean remove_prefixes(gchar *key, gpointer value, gpointer user_data)  gboolean
163    remove_prefixes (gchar * key, gpointer value, gpointer user_data)
164  {  {
165          g_free(key);    g_free (key);
166          return(TRUE);    return (TRUE);
167  }  }
168    
169  /* check if latex is available */  /* check if latex is available */
170  gboolean latexavailable(void)  gboolean
171    latexavailable (void)
172  {  {
173          gint status;    gint status;
174    
175          status = system("latex --version");    status = system ("latex --version");
176          if (status == 0) return(TRUE);    if (status == 0)
177          return(FALSE);      return (TRUE);
178      return (FALSE);
179  }  }
180    
181  /* free mem in state struct */  /* free mem in state struct */
182  static void freestate(void)  static void
183    freestate (void)
184  {  {
185          g_free(state.mylocation);    g_free (state.mylocation);
186          g_free(state.rigrst);    g_free (state.rigrst);
187  }  }
188    
189  /* free mem in prefs struct */  /* free mem in prefs struct */
190  static void freeprefs(void)  static void
191    freeprefs (void)
192  {  {
193          g_free(preferences.savedir);    g_free (preferences.savedir);
194  }  }
195    
196  /* free mem in remote struct */  /* free mem in remote struct */
197  static void freeremote(void)  static void
198    freeremote (void)
199  {  {
200          g_free(remote.program);    g_free (remote.program);
201  }  }
202    
203  /* cleanup of variables, used at exit */  /* cleanup of variables, used at exit */
204  void save_windowsize_and_cleanup(void) {  void
205          gint i;  save_windowsize_and_cleanup (void)
206    {
207      gint i;
208    
209          /* free the dxcc array */    /* free the dxcc array */
210          for (i = 0; i < state.countries; i++) {    for (i = 0; i < state.countries; i++)
211            g_free(dxcc[i].countryname);      {
212            g_free(dxcc[i].exceptions);        g_free (dxcc[i].countryname);
213          }        g_free (dxcc[i].exceptions);
214          g_free(dxcc);      }
215      g_free (dxcc);
216          /* free the qso array */  
217          for (i = 0; i < 20; i++)    /* free the qso array */
218                  g_free(qso[i]);    for (i = 0; i < 20; i++)
219          g_free(qso);      g_free (qso[i]);
220      g_free (qso);
221          g_list_free(logwindowlist);  
222      g_list_free (logwindowlist);
223          gdk_window_get_geometry(mainwindow->window, NULL, NULL, &preferences.width, &preferences.height, NULL);  
224          gdk_window_get_position(mainwindow->window, &preferences.x, &preferences.y);    gdk_window_get_geometry (mainwindow->window, NULL, NULL, &preferences.width,
225          savepreferences();                             &preferences.height, NULL);
226          savehistory();    gdk_window_get_position (mainwindow->window, &preferences.x,
227                               &preferences.y);
228      savepreferences ();
229      savehistory ();
230    
231  #if WANT_HAMLIB  #if WANT_HAMLIB
232          if (riglist) g_list_free(riglist);    if (riglist)
233          if (hamlibtimer != -1) gdk_input_remove(hamlibtimer);      g_list_free (riglist);
234          if (preferences.hamlib > 0) {    if (hamlibtimer != -1)
235                  rig_close((RIG *)myrig);      gdk_input_remove (hamlibtimer);
236                  rig_cleanup((RIG *)myrig);    if (preferences.hamlib > 0)
237          }      {
238          rig_close ((RIG *) myrig);
239          rig_cleanup ((RIG *) myrig);
240        }
241  #endif  #endif
242    
243          if (prefixes) {    if (prefixes)
244                  g_hash_table_foreach_remove(prefixes, (GHRFunc)remove_prefixes, NULL);      {
245                  g_hash_table_destroy(prefixes);        g_hash_table_foreach_remove (prefixes, (GHRFunc) remove_prefixes, NULL);
246          }        g_hash_table_destroy (prefixes);
247          g_strfreev(bandsplit);      }
248          g_strfreev(modesplit);    g_strfreev (bandsplit);
249          g_free(xlogdir);    g_strfreev (modesplit);
250          if (remotetimer != -1) gdk_input_remove(remotetimer);    g_free (xlogdir);
251          if (savetimer != -1) gdk_input_remove(savetimer);    if (remotetimer != -1)
252          if (clocktimer != -1) gdk_input_remove(clocktimer);      gdk_input_remove (remotetimer);
253              if (savetimer != -1)
254          /* remove message queue */      gdk_input_remove (savetimer);
255          if (msgid != -1) msgctl(msgid, IPC_RMID, 0);    if (clocktimer != -1)
256        gdk_input_remove (clocktimer);
257          /* detach shared mem and destroy it */  
258          if (state.shmid != -1) {    /* remove message queue */
259                  shmdt(shareCall);    if (msgid != -1)
260                  shmctl(state.shmid, IPC_RMID, NULL);      msgctl (msgid, IPC_RMID, 0);
261          }  
262      /* detach shared mem and destroy it */
263          freestate();    if (state.shmid != -1)
264          freeprefs();      {
265          freeremote();        shmdt (shareCall);
266          shmctl (state.shmid, IPC_RMID, NULL);
267        }
268    
269      freestate ();
270      freeprefs ();
271      freeremote ();
272  }  }
273    
274  /* find dot in frequency and return correct band */  /* find dot in frequency and return correct band */
275  gchar *finddot(gchar *qsoband)  gchar *
276    finddot (gchar * qsoband)
277  {  {
278          gchar *end, *j, *found = NULL;    gchar *end, *j, *found = NULL;
279            
280          end = qsoband + strlen(qsoband);    end = qsoband + strlen (qsoband);
281          for (j = qsoband; j < end; ++j)    for (j = qsoband; j < end; ++j)
282          {      {
283                  switch (*j)        switch (*j)
284                  {          {
285                          case '.':          case '.':
286                                  *j = '\0';            *j = '\0';
287                          break;            break;
288                  }          }
289          }      }
290          if (g_strcasecmp(qsoband, "1") == 0) found = g_strdup("1.8");    if (g_strcasecmp (qsoband, "1") == 0)
291          else if (g_strcasecmp(qsoband, "3") == 0) found = g_strdup("3.5");      found = g_strdup ("1.8");
292          else if (g_strcasecmp(qsoband, "7") == 0) found = g_strdup("7");    else if (g_strcasecmp (qsoband, "3") == 0)
293          else if (g_strcasecmp(qsoband, "29") == 0) found = g_strdup("28");      found = g_strdup ("3.5");
294          else found = g_strdup(qsoband);    else if (g_strcasecmp (qsoband, "7") == 0)
295          return(g_strdup(found));      found = g_strdup ("7");
296      else if (g_strcasecmp (qsoband, "29") == 0)
297        found = g_strdup ("28");
298      else
299        found = g_strdup (qsoband);
300      return (g_strdup (found));
301  }  }
302    
303  /* find dot in frequency and return string before the dot */  /* find dot in frequency and return string before the dot */
304  gchar *findint(gchar *freq)  gchar *
305    findint (gchar * freq)
306  {  {
307          gchar *end, *j;    gchar *end, *j;
308            
309          end = freq + strlen(freq);    end = freq + strlen (freq);
310          for (j = freq; j < end; ++j)    for (j = freq; j < end; ++j)
311          {      {
312                  switch (*j)        switch (*j)
313                  {          {
314                          case '.':          case '.':
315                                  *j = '\0';            *j = '\0';
316                          break;            break;
                 }  
317          }          }
318          return(freq);      }
319      return (freq);
320  }  }
321    
322  /* try to find the correct band for dupe checking */  /* try to find the correct band for dupe checking */
323  gchar *findband(gchar *arg)  gchar *
324    findband (gchar * arg)
325  {  {
326          long long fr;    long long fr;
327          gchar *str;    gchar *str;
328    
329          str = g_new0(gchar, 100);    str = g_new0 (gchar, 100);
330    
331          fr = atoll(arg);    fr = atoll (arg);
332    
333          if (fr > 1325) /* no dot */    if (fr > 1325)                /* no dot */
334          {      {
335                  sprintf(str, "%lld", fr);        sprintf (str, "%lld", fr);
336                  if (strlen(str) > 9)        if (strlen (str) > 9)
337                          str[strlen(str) - 9] = '\0';          str[strlen (str) - 9] = '\0';
338                  else if (strlen(str) > 6)        else if (strlen (str) > 6)
339                          str[strlen(str) - 6] = '\0';          str[strlen (str) - 6] = '\0';
340                  else if (strlen(str) > 3)        else if (strlen (str) > 3)
341                          str[strlen(str) - 3] = '\0';          str[strlen (str) - 3] = '\0';
342                  fr = atoll(str);        fr = atoll (str);
343          }      }
344            
345          switch (fr)    switch (fr)
346          {      {
347                  case 29:      case 29:
348                          fr = 28;        fr = 28;
349                  break;        break;
350                  case 50 ... 54:      case 50...54:
351                          fr = 50;        fr = 50;
352                  break;        break;
353                  case 144 ... 148:      case 144...148:
354                          fr = 144;        fr = 144;
355                  break;        break;
356                  case 222 ... 225:      case 222...225:
357                          fr = 222;        fr = 222;
358                  break;        break;
359                  case 420 ... 450:      case 420...450:
360                          fr = 420;        fr = 420;
361                  break;        break;
362                  case 902 ... 928:      case 902...928:
363                          fr = 902;        fr = 902;
364                  break;        break;
365                  case 1240 ... 1325:      case 1240...1325:
366                          fr = 1250;        fr = 1250;
367                  break;        break;
368                  default:      default:
369                  break;        break;
370          }      }
371          sprintf(str, "%lld", fr);    sprintf (str, "%lld", fr);
372          return(str);    return (str);
373  }  }
374    
375  /* get the current date, returned value has to be freed */  /* get the current date, returned value has to be freed */
376  gchar *getdate(void)  gchar *
377    getdate (void)
378  {  {
379          time_t current;    time_t current;
380          struct tm *timestruct = NULL;    struct tm *timestruct = NULL;
381          gchar sdatenow[20];    gchar sdatenow[20];
382    
383          time(&current);    time (&current);
384          timestruct = localtime(&current);    timestruct = localtime (&current);
385          strftime (sdatenow, 20, "%d %b %Y", timestruct);    strftime (sdatenow, 20, "%d %b %Y", timestruct);
386          return(g_strdup(sdatenow));    return (g_strdup (sdatenow));
387  }  }
388    
389  /* get the current time, returned value has to be freed */  /* get the current time, returned value has to be freed */
390  gchar *gettime(void)  gchar *
391    gettime (void)
392  {  {
393          time_t current;    time_t current;
394          struct tm *timestruct = NULL;    struct tm *timestruct = NULL;
395          gchar stimenow[20];    gchar stimenow[20];
396    
397          time(&current);    time (&current);
398          timestruct = localtime (&current);    timestruct = localtime (&current);
399          strftime (stimenow, 20, "%H%M", timestruct);    strftime (stimenow, 20, "%H%M", timestruct);
400          return(g_strdup(stimenow));    return (g_strdup (stimenow));
401  }  }
402    
403  /* look up mode in a list of modes */  /* look up mode in a list of modes */
404  gchar *lookup_mode(gchar *selectedmode)  gchar *
405    lookup_mode (gchar * selectedmode)
406  {  {
407          gint modeindex = 0;    gint modeindex = 0;
408    
409          for (;;)    for (;;)
410        {
411          if (g_strcasecmp (selectedmode, modesplit[modeindex]) == 0)
412          {          {
413                  if (g_strcasecmp(selectedmode, modesplit[modeindex]) == 0)            break;
                 {  
                         break;  
                 }  
                 modeindex++;  
414          }          }
415          return(g_strdup(modesplit[modeindex]));        modeindex++;
416        }
417      return (g_strdup (modesplit[modeindex]));
418  }  }
419    
420  /* look up band in a list of bands */  /* look up band in a list of bands */
421  gchar *lookup_band(gchar *selectedband)  gchar *
422    lookup_band (gchar * selectedband)
423  {  {
424          gint bandindex = 0;    gint bandindex = 0;
425    
426          for (;;)    for (;;)
427        {
428          if (g_strcasecmp (selectedband, bandsplit[bandindex]) == 0)
429          {          {
430                  if (g_strcasecmp(selectedband, bandsplit[bandindex]) == 0)            break;
                 {  
                         break;  
                 }  
                 bandindex++;  
431          }          }
432          return(g_strdup(bandsplit[bandindex]));        bandindex++;
433        }
434      return (g_strdup (bandsplit[bandindex]));
435  }  }
436    
437  /* clock which updates a label in the statusbar */  /* clock which updates a label in the statusbar */
438  gint updateclock(void)  gint
439    updateclock (void)
440  {  {
441          GtkWidget *clocklabel;    GtkWidget *clocklabel;
442          GString *timestr = g_string_new("");    GString *timestr = g_string_new ("");
443          gchar *nowdate, *nowtime;    gchar *nowdate, *nowtime;
444    
445          nowdate = getdate();    nowdate = getdate ();
446          nowtime = gettime();    nowtime = gettime ();
447          clocklabel = lookup_widget(mainwindow, "clocklabel");    clocklabel = lookup_widget (mainwindow, "clocklabel");
448          g_string_sprintf(timestr, "%s", nowdate);    g_string_sprintf (timestr, "%s", nowdate);
449          timestr = g_string_append_c(timestr, ' ');    timestr = g_string_append_c (timestr, ' ');
450          timestr = g_string_append(timestr, nowtime);    timestr = g_string_append (timestr, nowtime);
451          timestr = g_string_append(timestr, " GMT");    timestr = g_string_append (timestr, " GMT");
452          gtk_label_set_text(GTK_LABEL(clocklabel), timestr->str);    gtk_label_set_text (GTK_LABEL (clocklabel), timestr->str);
453          g_string_free(timestr, TRUE);    g_string_free (timestr, TRUE);
454          g_free(nowdate);    g_free (nowdate);
455          g_free(nowtime);    g_free (nowtime);
456          return 1;    return 1;
457  }  }
458    
459  /* Put color in the right format for XParseColor, so it can be processed by gdk_color_parse */  /* Put color in the right format for XParseColor, so it can be processed by gdk_color_parse */
460  gchar *color_parse(gchar *value)  gchar *
461    color_parse (gchar * value)
462  {  {
463          gchar **valuesplit = NULL;    gchar **valuesplit = NULL;
464          gchar *rgbsyntax;    gchar *rgbsyntax;
465            
466          valuesplit = g_strsplit(value, ",", 3);    valuesplit = g_strsplit (value, ",", 3);
467          rgbsyntax = g_strconcat("rgb:", valuesplit[0], "/", valuesplit[1], "/", valuesplit[2], NULL);    rgbsyntax =
468          g_strfreev(valuesplit);      g_strconcat ("rgb:", valuesplit[0], "/", valuesplit[1], "/",
469          return(rgbsyntax);                   valuesplit[2], NULL);
470      g_strfreev (valuesplit);
471      return (rgbsyntax);
472  }  }
473    
474  /* set style of a new row which has been added to the log */  /* set style of a new row which has been added to the log */
475  void setcallstyle(GtkWidget *clist, gint row, gchar *color, gchar *font)  void
476    setcallstyle (GtkWidget * clist, gint row, gchar * color, gchar * font)
477  {  {
478          GdkColor color2, color3, color4, themecolor;    GdkColor color2, color3, color4, themecolor;
479          GtkStyle *callstyle;    GtkStyle *callstyle;
480          gchar *newcolor;    gchar *newcolor;
481    
482          newcolor = color_parse(color);    newcolor = color_parse (color);
483          gdk_color_parse(newcolor, &themecolor);    gdk_color_parse (newcolor, &themecolor);
484          gdk_colormap_alloc_color(colormap, &themecolor, FALSE, TRUE);    gdk_colormap_alloc_color (colormap, &themecolor, FALSE, TRUE);
485          g_free(newcolor);    g_free (newcolor);
486            
487          /* colors other than the theme */    /* colors other than the theme */
488          color2.red = 0xffff;    /* white */    color2.red = 0xffff;          /* white */
489          color2.green = 0xffff;    color2.green = 0xffff;
490          color2.blue     = 0xffff;    color2.blue = 0xffff;
491          color3.red = 0xcccc;    /* light gray */    color3.red = 0xcccc;          /* light gray */
492          color3.green = 0xcccc;    color3.green = 0xcccc;
493          color3.blue     = 0xcccc;    color3.blue = 0xcccc;
494          color4.red = 0x4924;    /* dark slate blue */    color4.red = 0x4924;          /* dark slate blue */
495          color4.green = 0x3cf3;    color4.green = 0x3cf3;
496          color4.blue     = 0x8e38;    color4.blue = 0x8e38;
497    
498          /* set style of the new row */    /* set style of the new row */
499          callstyle = gtk_style_copy(clist->style);    callstyle = gtk_style_copy (clist->style);
500          callstyle->base[GTK_STATE_NORMAL] = themecolor;    callstyle->base[GTK_STATE_NORMAL] = themecolor;
501          callstyle->fg[GTK_STATE_NORMAL] = color2;    callstyle->fg[GTK_STATE_NORMAL] = color2;
502          callstyle->bg[GTK_STATE_SELECTED] = color3;    callstyle->bg[GTK_STATE_SELECTED] = color3;
503          callstyle->fg[GTK_STATE_SELECTED] = color4;    callstyle->fg[GTK_STATE_SELECTED] = color4;
504          gdk_font_unref(callstyle->font);    gdk_font_unref (callstyle->font);
505          if (!(callstyle->font = gdk_font_load(font)))    if (!(callstyle->font = gdk_font_load (font)))
506                  callstyle->font = gdk_font_load("-adobe-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*");      callstyle->font =
507          gtk_clist_set_cell_style(GTK_CLIST(clist), row, CALL, callstyle);        gdk_font_load ("-adobe-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*");
508      gtk_clist_set_cell_style (GTK_CLIST (clist), row, CALL, callstyle);
509  }  }
510    
511  /* get color style of a label */  /* get color style of a label */
512  gchar *getlabelcolor(GtkWidget *label)  gchar *
513    getlabelcolor (GtkWidget * label)
514  {  {
515          GtkStyle *labelstyle;    GtkStyle *labelstyle;
516          GdkColor labelcolor;    GdkColor labelcolor;
517          gchar *colorstr;    gchar *colorstr;
518            
519          labelstyle = gtk_style_copy(label->style);    labelstyle = gtk_style_copy (label->style);
520          labelcolor = labelstyle->fg[GTK_STATE_NORMAL];    labelcolor = labelstyle->fg[GTK_STATE_NORMAL];
521          colorstr = g_strdup_printf("%04X,%04X,%04X", labelcolor.red,    colorstr = g_strdup_printf ("%04X,%04X,%04X", labelcolor.red,
522                          labelcolor.green, labelcolor.blue);                                labelcolor.green, labelcolor.blue);
523          return(colorstr);    return (colorstr);
524  }  }
525    
526  /* set style of a label */  /* set style of a label */
527  void setlabelstyle(GtkWidget *label, gchar *color, gchar *font)  void
528    setlabelstyle (GtkWidget * label, gchar * color, gchar * font)
529  {  {
530          GtkStyle *labelstyle;    GtkStyle *labelstyle;
531          GdkColor themecolor;    GdkColor themecolor;
532          gchar *newcolor;    gchar *newcolor;
533    
534          newcolor = color_parse(color);    newcolor = color_parse (color);
535          gdk_color_parse(newcolor, &themecolor);    gdk_color_parse (newcolor, &themecolor);
536          if(!gdk_colormap_alloc_color(colormap, &themecolor, FALSE, TRUE))    if (!gdk_colormap_alloc_color (colormap, &themecolor, FALSE, TRUE))
537                  g_print("Allocation of color failed in setlabelstyle\n");      g_print ("Allocation of color failed in setlabelstyle\n");
538          labelstyle = gtk_style_copy(label->style);    labelstyle = gtk_style_copy (label->style);
539          labelstyle->fg[GTK_STATE_NORMAL] = themecolor;    labelstyle->fg[GTK_STATE_NORMAL] = themecolor;
540          gdk_font_unref(labelstyle->font);    gdk_font_unref (labelstyle->font);
541          if (!(labelstyle->font = gdk_font_load(font)))    if (!(labelstyle->font = gdk_font_load (font)))
542                  labelstyle->font = gdk_font_load("-adobe-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*");      labelstyle->font =
543          gtk_widget_set_style(GTK_WIDGET(label), labelstyle);        gdk_font_load ("-adobe-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*");
544          g_free(newcolor);    gtk_widget_set_style (GTK_WIDGET (label), labelstyle);
545      g_free (newcolor);
546  }  }
547    
548  /* set style of a frame */  /* set style of a frame */
549  void setframestyle(GtkWidget *frame, gchar *color, gchar *font)  void
550    setframestyle (GtkWidget * frame, gchar * color, gchar * font)
551  {  {
552          GtkStyle *framestyle;    GtkStyle *framestyle;
553          GdkColor themecolor;    GdkColor themecolor;
554          gchar *newcolor;    gchar *newcolor;
555    
556          newcolor = color_parse(color);    newcolor = color_parse (color);
557          gdk_color_parse(newcolor, &themecolor);    gdk_color_parse (newcolor, &themecolor);
558          if (!gdk_colormap_alloc_color(colormap, &themecolor, FALSE, TRUE))    if (!gdk_colormap_alloc_color (colormap, &themecolor, FALSE, TRUE))
559                  g_print("Allocation of color failed in setframestyle\n");      g_print ("Allocation of color failed in setframestyle\n");
560          framestyle = gtk_style_copy(frame->style);    framestyle = gtk_style_copy (frame->style);
561          framestyle->bg[GTK_STATE_NORMAL] = themecolor; /* frame */    framestyle->bg[GTK_STATE_NORMAL] = themecolor;        /* frame */
562          framestyle->fg[GTK_STATE_NORMAL] = themecolor; /* frame title */    framestyle->fg[GTK_STATE_NORMAL] = themecolor;        /* frame title */
563          gdk_font_unref(framestyle->font);    gdk_font_unref (framestyle->font);
564          if (!(framestyle->font = gdk_font_load(font)))    if (!(framestyle->font = gdk_font_load (font)))
565                  framestyle->font = gdk_font_load("-adobe-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*");      framestyle->font =
566          gtk_widget_set_style(GTK_WIDGET(frame), framestyle);        gdk_font_load ("-adobe-helvetica-bold-r-*-*-*-120-*-*-*-*-*-*");
567          g_free(newcolor);    gtk_widget_set_style (GTK_WIDGET (frame), framestyle);
568      g_free (newcolor);
569  }  }
570    
571    
572  gint autosave(void)  gint
573  {  autosave (void)
574          gint i;  {
575          logtype *logwindow;    gint i;
576          gchar *logfile, *temp;    logtype *logwindow;
577          gboolean message = FALSE;    gchar *logfile, *temp;
578      gboolean message = FALSE;
579          for (i = 0; i < g_list_length(logwindowlist); i++)  
580          {    for (i = 0; i < g_list_length (logwindowlist); i++)
581                  logwindow = g_list_nth_data(logwindowlist, i);      {
582                  if (logwindow->logchanged)        logwindow = g_list_nth_data (logwindowlist, i);
583                  {        if (logwindow->logchanged)
584                          logfile = g_strconcat(preferences.savedir, G_DIR_SEPARATOR_S, logwindow->logname, ".xlog", NULL);          {
585                          savelog(logwindow, logfile, TYPE_FLOG);            logfile =
586                          logwindow->logchanged = FALSE;              g_strconcat (preferences.savedir, G_DIR_SEPARATOR_S,
587                          gtk_label_set_text(GTK_LABEL(logwindow->label), logwindow->logname);                           logwindow->logname, ".xlog", NULL);
588                          g_free(logfile);            savelog (logwindow, logfile, TYPE_FLOG);
589                          message = TRUE;            logwindow->logchanged = FALSE;
590                  }            gtk_label_set_text (GTK_LABEL (logwindow->label),
591          }                                logwindow->logname);
592              g_free (logfile);
593          if (message)            message = TRUE;
594          {          }
595                  temp = g_strdup_printf(_("Log(s) autosaved"));      }
596                  update_statusbar(temp);  
597                  g_free(temp);    if (message)
598          }      {
599          return 1;        temp = g_strdup_printf (_("Log(s) autosaved"));
600          update_statusbar (temp);
601          g_free (temp);
602        }
603      return 1;
604  }  }
605    
606  /*  /*
607   * check visibility of fields in the loglist and show/hide the corresponding   * check visibility of fields in the loglist and show/hide the corresponding
608   * widgets in the QSO frame   * widgets in the QSO frame
609   */   */
610  void set_qsoframe(gpointer arg)  void
611    set_qsoframe (gpointer arg)
612  {  {
613          gint i, j;    gint i, j;
614          GtkWidget *endhbox, *powerhbox, *namehbox, *locatorhbox, *qthhbox,    GtkWidget *endhbox, *powerhbox, *namehbox, *locatorhbox, *qthhbox,
615                  *unknown1hbox, *unknown2hbox, *powerbutton, *powerlabel, *qslhbox,      *unknown1hbox, *unknown2hbox, *powerbutton, *powerlabel, *qslhbox,
616                  *locatorframe, *remarksvbox;      *locatorframe, *remarksvbox;
617          logtype *logw = (logtype *)arg;    logtype *logw = (logtype *) arg;
618    
619          for (i = 0; i < QSO_FIELDS; i++)    for (i = 0; i < QSO_FIELDS; i++)
620        {
621          for (j = 0; j < logw->columns; j++)
622          {          {
623                  for (j = 0; j < logw->columns; j++)            if (i == logw->logfields[j])
624                  {              break;
625                          if (i == logw->logfields[j]) break;          }
626                  }        if (i == GMTEND)
627                  if (i == GMTEND)          {
628                  {            endhbox = lookup_widget (mainwindow, "endhbox");
629                          endhbox = lookup_widget(mainwindow, "endhbox");            if (j == logw->columns)
630                          if (j == logw->columns)              gtk_widget_hide (endhbox);
631                                  gtk_widget_hide(endhbox);            else
632                          else              gtk_widget_show (endhbox);
633                                  gtk_widget_show(endhbox);          }
634                  }        else if (i == POWER)
635                  else if (i == POWER)          {
636                  {            powerhbox = lookup_widget (mainwindow, "powerhbox");
637                          powerhbox = lookup_widget(mainwindow, "powerhbox");            powerbutton = lookup_widget (mainwindow, "powerbutton");
638                          powerbutton = lookup_widget(mainwindow, "powerbutton");            powerlabel = lookup_widget (mainwindow, "powerlabel");
639                          powerlabel = lookup_widget(mainwindow, "powerlabel");            if (j == logw->columns)
640                          if (j == logw->columns)              gtk_widget_hide (powerhbox);
641                                  gtk_widget_hide(powerhbox);            else
642                          else              {
643                          {                gtk_widget_show (powerhbox);
644                                  gtk_widget_show(powerhbox);                if (preferences.hamlib > 0)
                                 if (preferences.hamlib > 0)  
                                 {  
                                         gtk_widget_show(powerbutton);  
                                         gtk_widget_hide(powerlabel);  
                                 }  
                                 else  
                                 {  
                                         gtk_widget_hide(powerbutton);  
                                         gtk_widget_show(powerlabel);  
                                 }  
                         }  
                 }  
                 else if (i == QSLOUT)  
                 {  
                         qslhbox = lookup_widget(mainwindow, "qslhbox");  
                         if (j == logw->columns)  
                                 gtk_widget_hide(qslhbox);  
                         else  
                                 gtk_widget_show(qslhbox);  
                 }  
                 else if (i == NAME)  
                 {  
                         namehbox = lookup_widget(mainwindow, "namehbox");  
                         if (j == logw->columns)  
                                 gtk_widget_hide(namehbox);  
                         else  
                                 gtk_widget_show(namehbox);  
                 }  
                 else if (i == QTH)  
                 {  
                         qthhbox = lookup_widget(mainwindow, "qthhbox");  
                         if (j == logw->columns)  
                                 gtk_widget_hide(qthhbox);  
                         else  
                                 gtk_widget_show(qthhbox);  
                 }  
                 else if (i == LOCATOR)  
                 {  
                         locatorhbox = lookup_widget(mainwindow, "locatorhbox");  
                         locatorframe = lookup_widget(mainwindow, "locatorframe");  
                         if (j == logw->columns)  
                         {  
                                 gtk_widget_hide(locatorhbox);  
                                 gtk_widget_hide(locatorframe);  
                         }  
                         else  
                         {  
                                 gtk_widget_show(locatorhbox);  
                                 gtk_widget_show(locatorframe);  
                         }  
                 }  
                 else if (i == U1)  
                 {  
                         unknown1hbox = lookup_widget(mainwindow, "unknown1hbox");  
                         if (j == logw->columns)  
                                 gtk_widget_hide(unknown1hbox);  
                         else  
                                 gtk_widget_show(unknown1hbox);  
                 }  
                 else if (i == U2)  
645                  {                  {
646                          unknown2hbox = lookup_widget(mainwindow, "unknown2hbox");                    gtk_widget_show (powerbutton);
647                          if (j == logw->columns)                    gtk_widget_hide (powerlabel);
                                 gtk_widget_hide(unknown2hbox);  
                         else  
                                 gtk_widget_show(unknown2hbox);  
648                  }                  }
649                  else if (i == REMARKS)                else
650                  {                  {
651                          remarksvbox = lookup_widget(mainwindow, "remarksvbox");                    gtk_widget_hide (powerbutton);
652                          if (j == logw->columns)                    gtk_widget_show (powerlabel);
                                 gtk_widget_hide(remarksvbox);  
                         else  
                                 gtk_widget_show(remarksvbox);  
653                  }                  }
654                }
655            }
656          else if (i == QSLOUT)
657            {
658              qslhbox = lookup_widget (mainwindow, "qslhbox");
659              if (j == logw->columns)
660                gtk_widget_hide (qslhbox);
661              else
662                gtk_widget_show (qslhbox);
663            }
664          else if (i == NAME)
665            {
666              namehbox = lookup_widget (mainwindow, "namehbox");
667              if (j == logw->columns)
668                gtk_widget_hide (namehbox);
669              else
670                gtk_widget_show (namehbox);
671            }
672          else if (i == QTH)
673            {
674              qthhbox = lookup_widget (mainwindow, "qthhbox");
675              if (j == logw->columns)
676                gtk_widget_hide (qthhbox);
677              else
678                gtk_widget_show (qthhbox);
679            }
680          else if (i == LOCATOR)
681            {
682              locatorhbox = lookup_widget (mainwindow, "locatorhbox");
683              locatorframe = lookup_widget (mainwindow, "locatorframe");
684              if (j == logw->columns)
685                {
686                  gtk_widget_hide (locatorhbox);
687                  gtk_widget_hide (locatorframe);
688                }
689              else
690                {
691                  gtk_widget_show (locatorhbox);
692                  gtk_widget_show (locatorframe);
693                }
694            }
695          else if (i == U1)
696            {
697              unknown1hbox = lookup_widget (mainwindow, "unknown1hbox");
698              if (j == logw->columns)
699                gtk_widget_hide (unknown1hbox);
700              else
701                gtk_widget_show (unknown1hbox);
702          }          }
703          else if (i == U2)
704            {
705              unknown2hbox = lookup_widget (mainwindow, "unknown2hbox");
706              if (j == logw->columns)
707                gtk_widget_hide (unknown2hbox);
708              else
709                gtk_widget_show (unknown2hbox);
710            }
711          else if (i == REMARKS)
712            {
713              remarksvbox = lookup_widget (mainwindow, "remarksvbox");
714              if (j == logw->columns)
715                gtk_widget_hide (remarksvbox);
716              else
717                gtk_widget_show (remarksvbox);
718            }
719        }
720  }  }
721    
722  gboolean fileexist(gchar *path)  gboolean
723    fileexist (gchar * path)
724  {  {
725          FILE *fp = NULL;    FILE *fp = NULL;
726    
727          fp = fopen(path, "r");    fp = fopen (path, "r");
728            
729          if (fp)    if (fp)
730          {      {
731                  fclose(fp);        fclose (fp);
732                  return(TRUE);        return (TRUE);
733          }      }
734          else return(FALSE);    else
735        return (FALSE);
736  }  }
737    
738  static gchar *strshift(gchar *str, size_t shift)  static gchar *
739    strshift (gchar * str, size_t shift)
740  {  {
741          gchar *start, *stop;    gchar *start, *stop;
742    
743          start = str;    start = str;
744          stop = str + strlen(str);    stop = str + strlen (str);
745          memmove(start + shift, start, stop-start+1);    memmove (start + shift, start, stop - start + 1);
746    
747          return(str + shift);    return (str + shift);
748  }  }
749    
750    
751  gchar *strreplace(gchar *str, const gchar *from, const gchar *to)  gchar *
752    strreplace (gchar * str, const gchar * from, const gchar * to)
753  {  {
754          gint tolen, fromlen, shift;    gint tolen, fromlen, shift;
755          gchar *start, *stop, *p;    gchar *start, *stop, *p;
756    
757          tolen = strlen(to);    tolen = strlen (to);
758          fromlen = strlen(from);    fromlen = strlen (from);
759          shift = tolen - fromlen;    shift = tolen - fromlen;
760          start = str;    start = str;
761          stop = str + strlen(str);    stop = str + strlen (str);
762    
763          while (NULL != (p = strstr(start, from)))    while (NULL != (p = strstr (start, from)))
764          {      {
765                  start = strshift(p + fromlen, shift);        start = strshift (p + fromlen, shift);
766                  stop  = stop + shift;        stop = stop + shift;
767                  memmove(p, to, tolen);        memmove (p, to, tolen);
768          }      }
769    
770          return str;    return str;
771  }  }
   

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26