aboutsummaryrefslogtreecommitdiffstats
path: root/composer/e-msg-composer-select-file.c
blob: c575a6d4ad6f369972a1b44bbcaab2608ce0f02e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Additional interfaces for the Controls used in configuration dialogs.
 *
 * Authors:
 *   Ettore Perazzoli <ettore@ximian.com>
 *
 * Copyright (C) 2002 Ximian, Inc.
 */

module GNOME {
module Evolution {
    interface ConfigControl : Bonobo::Unknown {
        /* Apply the current settings.  */
        void apply ();

        /* The actual Control.  */
        readonly attribute Bonobo::Control control;

        /* Get the event source for this control.  */
        readonly attribute Bonobo::EventSource eventSource;

        /* These are the events that get emitted when the properties of
           the dialog change:

             - "changed"

                Emitted when the data entered changes, and thus
                doesn't match the applied settings anymore.  The user must
                assume this to be true until ::apply gets invoked.
        */
    };
}; /* module Evolution */
}; /* module GNOME */
='#n121'>121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-msg-composer-select-file.c
 *
 * Copyright (C) 2000 Helix Code, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ettore Perazzoli
 */

#include <gtk/gtkfilesel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include "e-msg-composer-select-file.h"


struct _FileSelectionInfo {
    GtkWidget *widget;
    char *selected_file;
};
typedef struct _FileSelectionInfo FileSelectionInfo;


static void
confirm (FileSelectionInfo *info)
{
    const char *filename;

    filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (info->widget));
    info->selected_file = g_strdup (filename);

    gtk_widget_hide (info->widget);

    gtk_main_quit ();
}

static void
cancel (FileSelectionInfo *info)
{
    g_assert (info->selected_file == NULL);

    gtk_widget_hide (info->widget);

    gtk_main_quit ();
}


/* Callbacks.  */

static void
ok_clicked_cb (GtkWidget *widget,
           void *data)
{
    FileSelectionInfo *info;

    info = (FileSelectionInfo *) data;
    confirm (info);
}

static void
cancel_clicked_cb (GtkWidget *widget,
           void *data)
{
    FileSelectionInfo *info;

    info = (FileSelectionInfo *) data;
    cancel (info);
}

static int
delete_event_cb (GtkWidget *widget,
         GdkEventAny *event,
         void *data)
{
    FileSelectionInfo *info;

    info = (FileSelectionInfo *) data;
    cancel (info);

    return TRUE;
}


/* Setup.  */

static FileSelectionInfo *
create_file_selection (EMsgComposer *composer)
{
    FileSelectionInfo *info;
    GtkWidget *widget;
    GtkWidget *ok_button;
    GtkWidget *cancel_button;
    char *path;

    info = g_new (FileSelectionInfo, 1);

    widget        = gtk_file_selection_new (NULL);
    path = g_strdup_printf ("%s/", g_get_home_dir ());
    gtk_file_selection_set_filename (GTK_FILE_SELECTION (widget), path);
    g_free (path);
    gtk_window_set_wmclass (GTK_WINDOW (widget), "fileselection", 
                "Evolution:composer");
    ok_button     = GTK_FILE_SELECTION (widget)->ok_button;
    cancel_button = GTK_FILE_SELECTION (widget)->cancel_button;

    gtk_signal_connect (GTK_OBJECT (ok_button),
                "clicked", GTK_SIGNAL_FUNC (ok_clicked_cb), info);
    gtk_signal_connect (GTK_OBJECT (cancel_button),
                "clicked", GTK_SIGNAL_FUNC (cancel_clicked_cb), info);
    gtk_signal_connect (GTK_OBJECT (widget), "delete_event",
                GTK_SIGNAL_FUNC (delete_event_cb), info);

    info->widget        = widget;
    info->selected_file = NULL;

    return info;
}

static void
file_selection_info_destroy_notify (void *data)
{
    FileSelectionInfo *info;

    info = (FileSelectionInfo *) data;

    g_free (info->selected_file);
    g_free (info);
}


char *
e_msg_composer_select_file (EMsgComposer *composer,
                const char *title)
{
    FileSelectionInfo *info;
    char *retval;

    g_return_val_if_fail (composer != NULL, NULL);
    g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);

    info = gtk_object_get_data (GTK_OBJECT (composer),
                    "e-msg-composer-file-selection-info");

    if (info == NULL) {
        info = create_file_selection (composer);
        gtk_object_set_data_full (GTK_OBJECT (composer),
                      "e-msg-composer-file-selection-info", info,
                      file_selection_info_destroy_notify);
    }

    if (GTK_WIDGET_VISIBLE (info->widget))
        return NULL;        /* Busy!  */

    gtk_window_set_title (GTK_WINDOW (info->widget), title);
    gtk_widget_show (info->widget);

    GDK_THREADS_ENTER();
    gtk_main ();
    GDK_THREADS_LEAVE();

    retval = info->selected_file;
    info->selected_file = NULL;

    return retval;
}