aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-setup.c
blob: b1255906fbbbce123731e24b2398c0d5bb751dc3 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-setup.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.
 *
 */

/* This needs to be a lot better.  */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>
#include <gnome.h>

#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>

#include <gal/widgets/e-gui-utils.h>

#include "e-setup.h"


static GList *
check_dir_recur (const char *evolution_directory,
         const char *current_directory)
{
    DIR *def;
    GList *newfiles = NULL;
    struct dirent *current;

    def = opendir (current_directory);
    if (def == NULL)
        return NULL;

    current = readdir (def);
    while (current != NULL) {
        struct stat buf;
        char *fullname, *fulldefaultname;

        if (current->d_name[0] == '.' &&
            (current->d_name[1] == '\0' ||
             (current->d_name[1] == '.' && current->d_name[2] == '\0'))) {
            current = readdir (def);
            continue;
        }

        fullname = g_concat_dir_and_file (evolution_directory,
                          current->d_name);
        fulldefaultname = g_concat_dir_and_file (current_directory,
                             current->d_name);

        if (stat (fullname, &buf) == -1) {
            char *name;

            name = g_strdup (fulldefaultname);
            newfiles = g_list_append (newfiles, name);
        } else {
            if (S_ISDIR (buf.st_mode)) {
                newfiles = g_list_concat (newfiles,
                              check_dir_recur (fullname,
                                       fulldefaultname));
            }
        }

        g_free (fulldefaultname);
        g_free (fullname);
        current = readdir (def);
    }

    closedir (def);
    return newfiles;
}

static gboolean
check_evolution_directory (const char *evolution_directory)
{
    GtkWidget *dialog;
    GtkWidget *label1, *label2;
    gboolean retval;
    GList *newfiles, *l;
    char *defaultdir;
    int result;

    defaultdir = g_strdup (EVOLUTION_DATADIR "/evolution/default_user");
    newfiles = g_list_concat (NULL, check_dir_recur (evolution_directory,
                             defaultdir));

    if (newfiles == NULL) {
        retval = TRUE;
        goto out;
    }

    dialog = gnome_dialog_new (_("Evolution installation"),
                   GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL,
                   NULL);

    label1 = gtk_label_new (_("This new version of Evolution needs to install additional files\ninto your personal Evolution directory"));
    label2 = gtk_label_new (_("Please click \"OK\" to install the files, or \"Cancel\" to exit."));

    gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label1, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label2, TRUE, TRUE, 0);

    gtk_widget_show (label1);
    gtk_widget_show (label2);

    gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, TRUE, FALSE);

    result = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));

    if (result != 0) {
        retval = FALSE;
        goto out;
    }

    retval = TRUE;
    for (l = newfiles; l; l = l->next) {
        char *command;
        char *shortpath;

        shortpath = l->data + strlen (EVOLUTION_DATADIR "/evolution/default_user/");
        command = g_strconcat ("cp -r ",
                       l->data, " ",
                       evolution_directory, "/",
                       shortpath,
                       NULL);

        if (system (command) != 0) {
            retval = FALSE;
        } else {
            retval = (retval && TRUE);
        }

        g_free (command);
    }

    if (retval == FALSE)
        e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
              _("Could not update files correctly"));
    else
        e_notice (NULL, GNOME_MESSAGE_BOX_INFO,
              _("Evolution files successfully installed."));

 out:

    for (l = newfiles; l; l = l->next)
        g_free (l->data);

    g_list_free (newfiles);
    g_free (defaultdir);

    return retval;
}


static gboolean
copy_default_stuff (const char *evolution_directory)
{
    GtkWidget *dialog;
    GtkWidget *label1;
    GtkWidget *label2;
    GtkWidget *label3;
    gboolean retval;
    char *command;
    int result;

    dialog = gnome_dialog_new (_("Evolution installation"),
                   GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL,
                   NULL);

    label1 = gtk_label_new (_("This seems to be the first time you run Evolution."));
    label2 = gtk_label_new (_("Please click \"OK\" to install the Evolution user files under"));
    label3 = gtk_label_new (evolution_directory);

    gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label1, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label2, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label3, TRUE, TRUE, 0);

    gtk_widget_show (label1);
    gtk_widget_show (label2);
    gtk_widget_show (label3);

    gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, TRUE, FALSE);

    result = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
    if (result != 0)
        return FALSE;

    if (mkdir (evolution_directory, 0700)) {
        e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
              _("Cannot create the directory\n%s\nError: %s"),
              evolution_directory,
              g_strerror (errno));
        return FALSE;
    }

    command = g_strconcat ("cp -r ",
                   EVOLUTION_DATADIR,
                   "/evolution/default_user/* ",
                   evolution_directory,
                   NULL);

    if (system (command) != 0) {
        /* FIXME: Give more help.  */
        e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
              _("Cannot copy files into\n`%s'."), evolution_directory);
        retval = FALSE;
    } else {
        e_notice (NULL, GNOME_MESSAGE_BOX_INFO,
              _("Evolution files successfully installed."));
        retval = TRUE;
    }

    g_free (command);

    return retval;
}


gboolean
e_setup (const char *evolution_directory)
{
    struct stat statinfo;
    char *file;

    if (stat (evolution_directory, &statinfo) != 0)
        return copy_default_stuff (evolution_directory);

    if (! S_ISDIR (statinfo.st_mode)) {
        e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
              _("The file `%s' is not a directory.\n"
                "Please move it in order to allow installation\n"
                "of the Evolution user files."));
        return FALSE;
    }

    /* Make sure this is really our directory, not an Evolution
     * build tree or something like that.
     */
    file = g_strdup_printf ("%s/shortcuts.xml", evolution_directory);
    if (stat (file, &statinfo) != 0) {
        e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
              _("The directory `%s' exists but is not the\n"
                "Evolution directory.  Please move it in order\n"
                "to allow installation of the Evolution user "
                "files."), evolution_directory);
        g_free (file);
        return FALSE;
    }
    g_free (file);

    /* If the user has an old-style config file, replace it with
     * the new-style config directory. FIXME: This should be
     * temporary.
     */
    file = g_strdup_printf ("%s/config", evolution_directory);
    if (stat (file, &statinfo) == 0 && ! S_ISDIR (statinfo.st_mode)) {
        char *old = g_strdup_printf ("%s.old", file);
        rename (file, old);
        mkdir (file, 0700);
        g_free (old);
    }
    g_free (file);

    /* User has evolution directory...
       Check if it is up to date. */
    return check_evolution_directory (evolution_directory);
}
ntw44/cgit/freebsd-ports-gnome/commit/irc?h=dependabot/npm_and_yarn/devel/electron6/files/ini-1.3.8&id=6a020cee0496bba895aa6f99bdc6f5e234a43ad3'>- Mark BROKEN, fails to installbdrewery2013-08-301-5/+3 * - Attempt to fix parallel builds (-jX) by calling sub-makes correctlydanfe2013-08-301-6/+13 * - Remove Author linesunpoet2013-08-302-2/+0 * - Use single space after WWW:sunpoet2013-08-292-2/+2 * - Disconnect ports removed in r325546bdrewery2013-08-291-1/+0 * Update to latest GNUstep core libraries.theraven2013-08-294-285/+0 * Remove expired ports:rene2013-08-285-156/+0 * - Fix parallel (-jX) builds, drop vile MAKE_JOBS_UNSAFEdanfe2013-08-223-41/+42 * - Update to 0.52jadawin2013-08-213-35/+27 * - Unbreak parallel builds (-jX) by fixing make(1) syntax (still remains todanfe2013-08-212-27/+24 * irc/py-irc: update to 8.5.1wg2013-08-182-3/+3 * - Fix runtime crash due to gettextbdrewery2013-08-182-4/+30 * Take maintainershipbdrewery2013-08-181-1/+1 * - Reset yzlin's portsbdrewery2013-08-181-6/+2 * - Update to 20130812jase2013-08-174-10/+277 * - Remove MAKE_JOBS_SAFE variableak2013-08-159-9/+0 * irc/srvx: Mark jobs unsafemarino2013-08-141-5/+3 * irc/irssi-xmpp: Mark jobs unsafemarino2013-08-141-0/+2 * irc/py-irc: update to 8.5wg2013-08-112-3/+3 * Convert header, use USES, and pet portlint.adamw2013-08-112-7/+5 * irc/irc: Replace hardcoded "freebsd" with OPSYS:Lmarino2013-08-111-6/+2 * Update to 1.1.6jpaetzel2013-08-063-3/+4 * Update to 2.10.2jpaetzel2013-08-062-4/+3 * - Attempt to unbreak parallel (-jX) builds, remove MAKE_JOBS_UNSAFEdanfe2013-08-054-23/+48 * - Convert to new perl frameworkmat2013-08-031-2/+1 * - Convert to new perl frameworkaz2013-08-035-19/+9 * - Convert to new perl frameworkmat2013-08-033-3/+6 * - Update to 20130629jadawin2013-07-312-3/+3 * Fix my email address again, using proper @FreeBSD.org stylingfeld2013-07-291-1/+1 * Typo.mat2013-07-291-1/+1 * Deprecate and set expiration date for ports broken for more than 6 monthbapt2013-07-271-0/+3 * KDE3 and QT3 expired on 2013-07-01, remove these ports.rene2013-07-2718-643/+0 * - switch simple inline replacement from perl to sedaz2013-07-261-7/+2 * Update my email address throughout the treefeld2013-07-251-1/+1 * Remove MAKE_JOBS_SAFE which is now default.ehaupt2013-07-241-2/+0 * irc/py-irc: update to 8.4wg2013-07-233-10/+9 * - Update to 1.9.5miwi2013-07-224-203/+214 * - Install to KDE4_PREFIX when building with KDE support (should fix somemakc2013-07-202-24/+1 * irc/py-irc: update to 8.3.2wg2013-07-182-5/+4 * irc/irssi-xmpp: USES+= pkgconfigmarino2013-07-151-3/+2 * - Fix build with clang due to missing return valuebdrewery2013-07-131-5/+17 * - Update to 7.31.0sunpoet2013-07-124-1/+4 * Mark job unsafebapt2013-07-111-2/+2 * irc/py-irc: update to 8.3.1wg2013-07-063-20/+88 * Add LICENSEbdrewery2013-07-051-0/+2 * irc/znc: add rc.d scriptwg2013-06-272-0/+37 * - Update to 2.0.5swills2013-06-232-3/+3 * - Add dependency on pkgconfig to fix the failing build on 10-CURRENTashish2013-06-111-0/+1 * - Do not remove directories not created by this portmiwi2013-06-092-6/+1 * - Update to 2.0.4swills2013-06-052-8/+4 * Add patch to fix the static spell option [1].kwm2013-06-022-5/+14 * Add hexchat, which is a continuation of the XChat IRC client.kwm2013-06-0211-0/+364 * Actually remove bitchx-devel and add a VuXML entry.crees2013-05-319-330/+0 * Update to 1.2crees2013-05-319-373/+98 * - Do not try to remove dirs. not created by the portmiwi2013-05-311-1/+0 * - Update to 2.0.12swills2013-05-314-111/+69 * - Update MASTER_SITESmiwi2013-05-292-10/+13 * - Update MASTER_SITESmiwi2013-05-292-9/+25 * - Update MASTER_SITESmiwi2013-05-291-7/+10 * - Add patch to fix null pointer dereferences in webadmin modulejase2013-05-282-0/+39 * - Fix build with Tcl 8.6 by actually using CONFIGURE_ARGS when invoking CONFI...gahr2013-05-261-1/+1 * - Update to 0.4.1jase2013-05-243-25/+32 * - Update to 20130508jadawin2013-05-242-8/+4 * - Update to 8.3wg2013-05-172-4/+3 * - Change MAINTAINER address of all my portswg2013-05-161-1/+1 * - Bump PORTREVISION after dns/c-ares updatezi2013-05-162-4/+6 * - Update to 20130514 (0.4.1-rc2)jase2013-05-162-4/+4 * - Fix build with Tcl/Tk 8.6gahr2013-05-155-5/+39 * - Restore the correct USE_TK value range, was inadvertently changed in mygahr2013-05-141-1/+1 * - Fix build with Tcl 8.6 [1]gahr2013-05-142-12/+27 * - Fix build with Tcl 8.6gahr2013-05-142-0/+353 * - add MASTER_SITESdinoex2013-05-132-3/+1 * - Add missing sharedmime to the list of USE_KDE4 components. It will bemakc2013-05-132-3/+1 * - Add global options (DOCS, NLS, etc) to the OPTIONS_DEFINE and partly revert...makc2013-05-121-8/+4 * - Update to 0.9.0makc2013-05-124-24/+133 * - Update to 20130507 (0.4.1-rc1)jase2013-05-123-6/+21 * Fix shebang_file listbapt2013-05-101-1/+1 * Add some shebangfix to allow building most of the ports tree without /usr/bin...bapt2013-05-071-1/+3 * - Convert to use shebangfix USES flagehaupt2013-05-072-23/+17 * Convert USE_NCURSES by USES=ncursesbapt2013-05-064-15/+11 * Convert from WITHOUT_NLS to PORT_OPTIONS:MNLSbapt2013-05-061-6/+4 * Fix installation of ports that rely on cp -n for installing files. r245960flo2013-05-051-2/+2 * Fix build with bmakebapt2013-05-041-0/+2 * Chase security/libgcrypt updateehaupt2013-05-045-4/+6 * - Convert USE_ICONV=yes to USES=iconvmva2013-04-276-9/+6 * - Convert USE_GETTEXT to USES (part 4)ak2013-04-264-6/+4 * - Convert USE_GETTEXT to USES (part 3)ak2013-04-253-3/+3 * - Chase x11-toolkits/fox16 shlib version bumpgahr2013-04-241-0/+1 * - Remove lang/tcl83 and x11-toolkits/tk83 (expired)gahr2013-04-232-2/+2 * Convert irc to USES=pkgconfigbapt2013-04-239-23/+11 * Trim header, convert OptionsNG.kwm2013-04-171-47/+25 * Fix conversion to new option frameworkbapt2013-04-041-6/+6 * GNU Emacs updatesashish2013-03-301-0/+1 * For perl@ owned ports:eadler2013-03-292-12/+4 * Style: tab -> space.eadler2013-03-294-4/+4 * Mechanically convert unmaintained ports which use "gnomehack" to use "pathfix...eadler2013-03-281-6/+3 * Convert left unconverted ports in irc to new options frameworkbapt2013-03-2610-259/+198 * - Unbreak buildmiwi2013-03-261-1/+1 * Add NLS to OPTIONS_DEFINEmakc2013-03-251-0/+1 * Update to 1.1.5jpaetzel2013-03-252-3/+3 * - Add explicit pkgconf dependencybdrewery2013-03-241-5/+2 * - Update to 0.97wen2013-03-232-9/+5 * - convert USE_CMAKE to USESmakc2013-03-237-7/+7 * - add missin build dependency on pytest-runnerrm2013-03-231-1/+3 * This changes almost all the "gnomehack" only USE_GNOME cases to USES= pathfix.eadler2013-03-193-3/+3 * - Convert to PEAR_AUTOINSTALLmiwi2013-03-151-86/+3 * - Fix implicit dependency on iconv and opensslbeech2013-03-127-6/+194 * Remove indefinite article from COMMENTehaupt2013-03-081-6/+2 * * Update the glib to 2.34.3 and gtk20 to 2.24.17 and gtk30 to 3.6.4 whichkwm2013-03-085-45/+35 * - Update to 20.2,1beech2013-03-084-15/+35 * - Please welcome back Chris Petrik as maintainer ofbdrewery2013-03-072-7/+3 * - Prep for removal of BUILD_DEPENDS=eggdropbdrewery2013-03-061-2/+3 * - update to 3.29dinoex2013-03-043-4/+7 * - Update to 20130301jase2013-03-013-17/+6 * -Fix build with clangbeech2013-02-266-5/+67 * POE::Component::IRC::Plugin::Karma - plugin to store karmaswills2013-02-205-0/+45 * - Correct the distinfo after we switched to githubmiwi2013-02-191-2/+2 * - Update to 8.0.1culot2013-02-192-3/+3 * - Correct the Created by line with the Real namemiwi2013-02-181-1/+1 * - Switch to USE_GITHUBmiwi2013-02-181-6/+7 * - Update to 2.0.10swills2013-02-182-15/+9 * - Add missing depspawel2013-02-091-7/+4 * - Add UPDATING entry for gnutls updatenovel2013-02-069-7/+12 * - Update to ircd-hybrid 8.0.4db2013-02-0514-642/+273 * - Update to v3.2brix2013-02-052-33/+37 * - Remove irc/zircon and math/lensnns, both expired and abandonedgahr2013-02-049-387/+0 * - Update to 6.81miwi2013-02-042-4/+6 * - Fix all cases of 'No newline at end of file' in ports treeak2013-02-011-1/+1 * - cleanup headerdinoex2013-01-273-14/+3 * - Update to 1.7sbz2013-01-223-25/+19 * - Update to 1.0.5.araujo2013-01-213-48/+41 * - Update to 20130120 (0.4.1-dev)jase2013-01-212-5/+7 * - Update to 0.4.0jase2013-01-214-17/+39 * Interactivity is now an OPTION, thus making a package availablecrees2013-01-1812-284/+311 * Stop being INTERACTIVEcrees2013-01-181-9/+24 * Stop being INTERACTIVEcrees2013-01-183-19/+45 * - Update to 8.0culot2013-01-182-3/+6 * - Update to 20130114 (0.4.0-rc3)jase2013-01-172-4/+4