Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

dialog-time.cpp File Reference

#include <gtk/gtk.h>
#include <time.h>
#include <celengine/astro.h>
#include <celengine/simulation.h>
#include "dialog-time.h"
#include "common.h"

Include dependency graph for dialog-time.cpp:

Go to the source code of this file.

Functions

static void chooseOption (GtkWidget *hbox, const char *str, char *choices[], int *val, GtkSignalFunc chosen)
void dialogSetTime (AppData *app)
static gboolean intAdjChanged (GtkAdjustment *adj, int *val)
static void intSpin (GtkWidget *hbox, const char *str, int min, int max, int *val, const char *sep)
static gboolean monthChosen (GtkComboBox *menu, int *month)
static gboolean zoneChosen (GtkComboBox *menu, gboolean *timezone)
static gboolean zoneChosen (GtkComboBox *menu, int *timezone)


Function Documentation

static void chooseOption GtkWidget *  hbox,
const char *  str,
char *  choices[],
int *  val,
GtkSignalFunc  chosen
[static]
 

Definition at line 149 of file dialog-time.cpp.

Referenced by dialogSetTime().

00150 {
00151         GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
00152         GtkWidget *label = gtk_label_new(str);
00153         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
00154         GtkWidget* combo = gtk_combo_box_new_text();
00155         
00156         for(unsigned int i = 0; choices[i]; i++)
00157         {
00158                 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), choices[i]);
00159         }
00160         
00161         gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
00162         gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, TRUE, 7);
00163         gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 2);
00164         
00165         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), (*val - 1));
00166 
00167         g_signal_connect(GTK_OBJECT(combo), "changed", G_CALLBACK(chosen), (gpointer)val);
00168 }

void dialogSetTime AppData app  ) 
 

Definition at line 36 of file dialog-time.cpp.

References chooseOption(), intSpin(), monthChosen(), monthOptions, astro::secondsToJulianDate(), tzOffsetAtDate(), and zoneChosen().

Referenced by actionTimeSet().

00037 {
00038         int timezone = 1;
00039         
00040         GtkWidget *stimedialog = gtk_dialog_new_with_buttons("Set Time",
00041                                                              GTK_WINDOW(app->mainWindow),
00042                                                              GTK_DIALOG_DESTROY_WITH_PARENT,
00043                                                              GTK_STOCK_OK,
00044                                                              GTK_RESPONSE_OK,
00045                                                              "Set Current Time",
00046                                                              GTK_RESPONSE_ACCEPT,
00047                                                              GTK_STOCK_CANCEL,
00048                                                              GTK_RESPONSE_CANCEL,
00049                                                              NULL);
00050 
00051         if (app->showLocalTime)
00052                 timezone = 2;
00053         
00054         GtkWidget *hbox = gtk_hbox_new(FALSE, 6);
00055         GtkWidget *frame = gtk_frame_new("Time");
00056         GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
00057 
00058         astro::Date date(app->simulation->getTime() +
00059                          astro::secondsToJulianDate(app->core->getTimeZoneBias()));
00060 
00061         gtk_widget_show(align);
00062         gtk_widget_show(frame);
00063         gtk_container_add(GTK_CONTAINER(align),GTK_WIDGET(hbox));
00064         gtk_container_add(GTK_CONTAINER(frame),GTK_WIDGET(align));
00065         gtk_container_set_border_width (GTK_CONTAINER (frame), 7);
00066         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(stimedialog)->vbox), frame, FALSE, FALSE, 0);
00067     
00068         int seconds = (int)date.seconds;
00069         intSpin(hbox, "Hour", 0, 23, &date.hour, ":");
00070         intSpin(hbox, "Minute", 0, 59, &date.minute, ":");
00071         intSpin(hbox, "Second", 0, 59, &seconds, "  ");
00072 
00073         chooseOption(hbox,
00074                      "Timezone",
00075                      (char **)timeOptions,
00076                      &timezone,
00077                      GTK_SIGNAL_FUNC(zoneChosen));
00078         
00079         gtk_widget_show_all(hbox);
00080         hbox = gtk_hbox_new(FALSE, 6);
00081         frame = gtk_frame_new("Date");
00082         align=gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
00083         gtk_container_set_border_width (GTK_CONTAINER (frame), 7);
00084 
00085         chooseOption(hbox,
00086                      "Month",
00087                      (char **)monthOptions,
00088                      &date.month,
00089                      GTK_SIGNAL_FUNC(monthChosen));
00090         
00091         /* (Hopefully, noone will need to go beyond these years :-) */
00092         intSpin(hbox, "Day", 1, 31, &date.day, ",");
00093         intSpin(hbox, "Year", -9999, 9999, &date.year, " ");
00094 
00095         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(stimedialog)->vbox), frame, FALSE, FALSE, 0);
00096         gtk_container_add(GTK_CONTAINER(align),GTK_WIDGET(hbox));
00097         gtk_container_add(GTK_CONTAINER(frame),GTK_WIDGET(align));
00098         gtk_widget_show(align);
00099         gtk_widget_show(frame);
00100         gtk_widget_show_all(hbox);
00101 
00102         gtk_dialog_set_default_response(GTK_DIALOG(stimedialog), GTK_RESPONSE_OK);
00103         gint button = gtk_dialog_run(GTK_DIALOG(stimedialog));
00104 
00105         /* Set the selected seconds value back to the Date struct */
00106         date.seconds = seconds;
00107 
00108         if (button == GTK_RESPONSE_ACCEPT)
00109                 /* Set current time and exit. */
00110                 app->simulation->setTime((double)time(NULL) / 86400.0 + (double)astro::Date(1970, 1, 1));
00111         else if (button == GTK_RESPONSE_OK)
00112                 /* Set entered time and exit */
00113                 app->simulation->setTime((double)date - ((timezone == 1) ? 0 : astro::secondsToJulianDate(tzOffsetAtDate(date))));
00114 
00115         gtk_widget_destroy(stimedialog);
00116 }

static gboolean intAdjChanged GtkAdjustment *  adj,
int *  val
[static]
 

Definition at line 120 of file dialog-time.cpp.

Referenced by intSpin().

00121 {
00122         if (val)
00123         {
00124                 *val = (int)adj->value;
00125                 return TRUE;
00126         }
00127         return FALSE;
00128 }

static void intSpin GtkWidget *  hbox,
const char *  str,
int  min,
int  max,
int *  val,
const char *  sep
[static]
 

Definition at line 172 of file dialog-time.cpp.

References intAdjChanged(), max, and min.

Referenced by dialogSetTime().

00173 {
00174         GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
00175         GtkWidget *label = gtk_label_new(str);
00176         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
00177         GtkAdjustment *adj = (GtkAdjustment *) gtk_adjustment_new ((float)*val, (float) min, (float) max,
00178                                                                    1.0, 5.0, 0.0);
00179         GtkWidget *spinner = gtk_spin_button_new (adj, 1.0, 0);
00180         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON (spinner), TRUE);
00181         gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
00182         gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON (spinner),TRUE);
00183         gtk_entry_set_max_length(GTK_ENTRY (spinner), ((max<99)?2:4) );
00184 
00185         gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
00186         gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
00187         
00188         if ((sep) && (*sep))
00189         {
00190                 gtk_widget_show (label);
00191                 GtkWidget *hbox2 = gtk_hbox_new(FALSE, 3);
00192                 label = gtk_label_new(sep);
00193                 gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
00194                 gtk_box_pack_start (GTK_BOX (hbox2), spinner, FALSE, FALSE, 0);
00195                 gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
00196                 gtk_box_pack_start (GTK_BOX (vbox), hbox2, TRUE, TRUE, 7);
00197                 gtk_widget_show (label);
00198                 gtk_widget_show (hbox2);
00199         }
00200         else
00201         {
00202                 gtk_box_pack_start (GTK_BOX (vbox), spinner, TRUE, TRUE, 7);
00203         }
00204 
00205         g_signal_connect(GTK_OBJECT(adj), "value-changed",
00206                          G_CALLBACK(intAdjChanged), val);
00207 }

static gboolean monthChosen GtkComboBox *  menu,
int *  month
[static]
 

Definition at line 140 of file dialog-time.cpp.

Referenced by dialogSetTime().

00141 {
00142         if (month)
00143                 *month = gtk_combo_box_get_active(menu) + 1;
00144         return TRUE;
00145 }

static gboolean zoneChosen GtkComboBox *  menu,
gboolean *  timezone
[static]
 

Definition at line 132 of file dialog-time.cpp.

00133 {
00134         *timezone = gtk_combo_box_get_active(menu) + 1;
00135         return TRUE;
00136 }

static gboolean zoneChosen GtkComboBox *  menu,
int *  timezone
[static]
 

Referenced by dialogSetTime().


Generated on Sat Jan 14 22:31:56 2006 for Celestia by  doxygen 1.4.1