2011-09-20 19:40:34 +00:00
|
|
|
/* info.c */
|
|
|
|
/* creates the UI for the info frame -
|
|
|
|
* controlled through the following interfaces:
|
|
|
|
*
|
|
|
|
* void flush_dive_info_changes(struct dive *dive)
|
|
|
|
* void show_dive_info(struct dive *dive)
|
|
|
|
*
|
|
|
|
* called from gtk-ui:
|
|
|
|
* GtkWidget *extended_dive_info_widget(void)
|
|
|
|
*/
|
2011-08-31 19:09:19 +00:00
|
|
|
#include <stdio.h>
|
2011-09-03 03:00:10 +00:00
|
|
|
#include <string.h>
|
2011-08-31 19:09:19 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "dive.h"
|
|
|
|
#include "display.h"
|
2011-09-20 19:40:34 +00:00
|
|
|
#include "display-gtk.h"
|
2011-09-05 19:12:58 +00:00
|
|
|
#include "divelist.h"
|
2011-08-31 19:09:19 +00:00
|
|
|
|
2011-09-13 21:58:06 +00:00
|
|
|
static GtkEntry *location, *buddy, *divemaster;
|
2011-09-04 12:38:01 +00:00
|
|
|
static GtkTextBuffer *notes;
|
2011-09-02 02:56:04 +00:00
|
|
|
static int location_changed = 1, notes_changed = 1;
|
2011-09-13 21:58:06 +00:00
|
|
|
static int divemaster_changed = 1, buddy_changed = 1;
|
2011-09-01 03:36:51 +00:00
|
|
|
|
2011-09-02 02:56:04 +00:00
|
|
|
static char *get_text(GtkTextBuffer *buffer)
|
|
|
|
{
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &end);
|
|
|
|
return gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
|
|
|
|
}
|
|
|
|
|
2011-09-10 00:10:17 +00:00
|
|
|
void flush_dive_info_changes(struct dive *dive)
|
2011-09-02 02:56:04 +00:00
|
|
|
{
|
|
|
|
if (!dive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (location_changed) {
|
|
|
|
g_free(dive->location);
|
2011-09-04 12:38:01 +00:00
|
|
|
dive->location = gtk_editable_get_chars(GTK_EDITABLE(location), 0, -1);
|
2011-09-02 02:56:04 +00:00
|
|
|
}
|
|
|
|
|
2011-09-13 21:58:06 +00:00
|
|
|
if (divemaster_changed) {
|
|
|
|
g_free(dive->divemaster);
|
|
|
|
dive->divemaster = gtk_editable_get_chars(GTK_EDITABLE(divemaster), 0, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buddy_changed) {
|
|
|
|
g_free(dive->buddy);
|
|
|
|
dive->buddy = gtk_editable_get_chars(GTK_EDITABLE(buddy), 0, -1);
|
|
|
|
}
|
|
|
|
|
2011-09-02 02:56:04 +00:00
|
|
|
if (notes_changed) {
|
|
|
|
g_free(dive->notes);
|
|
|
|
dive->notes = get_text(notes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 19:39:35 +00:00
|
|
|
#define SET_TEXT_ENTRY(x) \
|
|
|
|
gtk_entry_set_text(x, dive && dive->x ? dive->x : "")
|
2011-09-02 02:56:04 +00:00
|
|
|
|
2011-09-19 19:39:35 +00:00
|
|
|
void show_dive_info(struct dive *dive)
|
2011-09-01 03:36:51 +00:00
|
|
|
{
|
2011-09-20 05:09:47 +00:00
|
|
|
struct tm *tm;
|
|
|
|
const char *text;
|
|
|
|
char buffer[80];
|
|
|
|
|
|
|
|
/* dive number and location (or lacking that, the date) go in the window title */
|
|
|
|
tm = gmtime(&dive->when);
|
|
|
|
text = dive->location;
|
|
|
|
if (!text)
|
|
|
|
text = "";
|
|
|
|
if (*text) {
|
|
|
|
snprintf(buffer, sizeof(buffer), "Dive #%d - %s", dive->number, text);
|
|
|
|
} else {
|
|
|
|
snprintf(buffer, sizeof(buffer), "Dive #%d - %s %02d/%02d/%04d at %d:%02d",
|
|
|
|
dive->number,
|
|
|
|
weekday(tm->tm_wday),
|
|
|
|
tm->tm_mon+1, tm->tm_mday,
|
|
|
|
tm->tm_year+1900,
|
|
|
|
tm->tm_hour, tm->tm_min);
|
|
|
|
}
|
|
|
|
text = buffer;
|
|
|
|
if (!dive->number)
|
|
|
|
text += 10; /* Skip the "Dive #0 - " part */
|
|
|
|
gtk_window_set_title(GTK_WINDOW(main_window), text);
|
|
|
|
|
2011-09-19 19:39:35 +00:00
|
|
|
SET_TEXT_ENTRY(divemaster);
|
|
|
|
SET_TEXT_ENTRY(buddy);
|
|
|
|
SET_TEXT_ENTRY(location);
|
|
|
|
gtk_text_buffer_set_text(notes, dive && dive->notes ? dive->notes : "", -1);
|
2011-09-01 01:30:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-04 12:38:01 +00:00
|
|
|
static GtkEntry *text_entry(GtkWidget *box, const char *label)
|
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *frame = gtk_frame_new(label);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
|
|
|
|
|
2011-09-11 23:34:01 +00:00
|
|
|
entry = gtk_entry_new();
|
2011-09-04 12:38:01 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(frame), entry);
|
|
|
|
|
|
|
|
return GTK_ENTRY(entry);
|
|
|
|
}
|
|
|
|
|
2011-09-11 23:34:01 +00:00
|
|
|
static GtkTextBuffer *text_view(GtkWidget *box, const char *label)
|
2011-09-01 03:36:51 +00:00
|
|
|
{
|
2011-09-11 23:34:01 +00:00
|
|
|
GtkWidget *view, *vbox;
|
2011-09-02 02:56:04 +00:00
|
|
|
GtkTextBuffer *buffer;
|
2011-09-01 03:36:51 +00:00
|
|
|
GtkWidget *frame = gtk_frame_new(label);
|
2011-09-02 02:56:04 +00:00
|
|
|
|
2011-09-11 23:34:01 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
|
|
|
|
box = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(frame), box);
|
|
|
|
vbox = gtk_vbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(box), vbox);
|
2011-09-02 02:56:04 +00:00
|
|
|
|
2011-09-11 23:34:01 +00:00
|
|
|
GtkWidget* scrolled_window = gtk_scrolled_window_new(0, 0);
|
2011-09-04 13:08:01 +00:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2011-09-04 00:37:22 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
|
|
|
|
gtk_widget_show(scrolled_window);
|
|
|
|
|
2011-09-11 23:34:01 +00:00
|
|
|
view = gtk_text_view_new();
|
2011-09-04 13:08:01 +00:00
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
|
2011-09-04 00:37:22 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(scrolled_window), view);
|
|
|
|
|
2011-09-02 02:56:04 +00:00
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
|
|
|
|
2011-09-11 23:34:01 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
|
2011-09-02 02:56:04 +00:00
|
|
|
return buffer;
|
2011-09-01 03:36:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-04 17:01:30 +00:00
|
|
|
GtkWidget *extended_dive_info_widget(void)
|
2011-09-01 01:30:42 +00:00
|
|
|
{
|
2011-09-13 21:58:06 +00:00
|
|
|
GtkWidget *vbox, *hbox;
|
2011-09-04 15:08:40 +00:00
|
|
|
vbox = gtk_vbox_new(FALSE, 6);
|
2011-09-01 01:30:42 +00:00
|
|
|
|
2011-09-04 15:08:40 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
|
2011-09-13 21:58:06 +00:00
|
|
|
location = text_entry(vbox, "Location");
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
|
|
|
|
|
|
|
|
divemaster = text_entry(hbox, "Divemaster");
|
|
|
|
buddy = text_entry(hbox, "Buddy");
|
|
|
|
|
2011-09-11 23:34:01 +00:00
|
|
|
notes = text_view(vbox, "Notes");
|
2011-09-04 15:08:40 +00:00
|
|
|
return vbox;
|
2011-08-31 19:09:19 +00:00
|
|
|
}
|