1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
36 void set_defaults (void) {
38 if (conf
.spawn_command
== NULL
) conf
.spawn_command
= g_strdup(spawn_commands
[0].command
);
40 conf_verify_a_host_exists();
41 if (conf
.cfuserinterval
== 0) conf
.cfuserinterval
= 30;
42 cf_threshold_normalize(&conf
.cfthreshold
);
47 static void try_remote_command (JamAccount
*acc
) {
48 const char *username
= (acc
? jam_account_get_username(acc
) : NULL
);
50 /* send the remote command.
51 * you'd think we'd want to conditionally do this on the configuration
52 * option, but you'd be wrong. :)
53 * if the setting in the conf is "allow multiple instances", but then
54 * the user changes the setting to "only one instance" in the ui and then
55 * runs another copy of logjam, it's counterintuitive for it to ignore that
56 * changed ui setting, even if it hadn't got propogated to the
57 * configuration file yet.
58 * so we always try to use the socket. the conf setting is only
59 * used when we consider *creating* the socket. */
60 /* a null username just brings the window to the foreground. */
61 if (remote_send_user(username
, &err
)) {
62 /* we popped up another window, so we're done. */
63 g_print(_("Bringing already-running LogJam instance to the " "foreground...\n"));
66 g_printerr(_("Error sending remote command: %s.\n"), err
->message
);
74 static void init_app (int *argc
, gchar
*argv
[]) {
76 memset(&app
, 0, sizeof(Application
));
77 app
.programname
= argv
[0]; /* not the same as PROGRAMNAME */
78 /* treatment of configuration dir; must be done before read_conf */
79 for (i
= 1; i
< *argc
; i
++) { /* look for arg */
80 if (!strcmp(argv
[i
], "--conf-dir")) {
81 app
.conf_dir
= argv
[i
+ 1];
85 if (g_strrstr(argv
[i
], "--conf-dir=")) {
86 app
.conf_dir
= argv
[i
] + strlen("--conf-dir=");
92 /* shift what comes after */
94 for (; i
< *argc
; ++i
) argv
[i
] = argv
[i
+shift
];
96 if (!app
.conf_dir
) app
.conf_dir
= g_strdup_printf("%s/.logjam", g_get_home_dir());
98 app
.tooltips
= gtk_tooltips_new();
99 gtk_tooltips_enable(app
.tooltips
);
105 static void run_gtk (JamDoc
*doc
) {
107 app
.remote
= logjam_remote_new();
108 accelpath
= g_build_filename(app
.conf_dir
, "accels", NULL
);
109 gtk_accel_map_load(accelpath
);
111 /* the 99% common case is the user has a username/password/host remembered
112 * and they just want to use those. */
113 if (!jam_doc_get_account(doc
)) {
114 JamAccount
*acc
= NULL
;
115 if (conf
.lasthost
&& conf
.lasthost
->lastaccount
&& conf
.lasthost
->lastaccount
->remember_password
) {
116 acc
= conf
.lasthost
->lastaccount
;
117 if (JAM_ACCOUNT_IS_LJ(acc
)) login_check_lastupdate(NULL
, JAM_ACCOUNT_LJ(acc
));
119 acc
= login_dlg_run(NULL
, conf
.lasthost
, acc
);
122 jam_doc_set_account(doc
, acc
);
125 g_object_unref(G_OBJECT(app
.remote
));
126 gtk_accel_map_save(accelpath
);
133 static void setup_locales (void) {
134 /* This call actually initializes the locale settings,
135 * and doesn't just clear LC_ALL (which is sorta what
136 * it looks like it's doing). */
137 setlocale(LC_ALL
, "");
139 bindtextdomain(GETTEXT_PACKAGE
, LOCALEDIR
);
140 /* GTK always wants UTF-8 strings.
141 * gettext will try to translate to the current locale's codeset
142 * unless we tell it to leave it in UTF-8. */
143 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8");
144 textdomain(GETTEXT_PACKAGE
);
149 static void setup_glibgdk (void) {
151 /* calls to these thread inits must happen before any other
153 if (!g_thread_supported()) g_thread_init(NULL
);
156 #endif /* HAVE_GTK */
158 g_set_application_name(_("LogJam"));
162 int main (int argc
, char *argv
[]) {
171 init_app(&argc
, argv
); /* should be called before conf_read */
172 conf_read(&conf
, app
.conf_dir
);
174 jam_account_logjam_init();
177 has_gtk
= gtk_init_check(&argc
, &argv
);
181 cmdline_parse(doc
, argc
, argv
); /* may terminate. */
185 g_printerr(_("GTK init failed -- are you in X?\n"));
186 g_printerr(_("Run %s --help for command-line options.\n"), app
.programname
);
189 try_remote_command(jam_doc_get_account(doc
));
192 g_printerr(_("Error: No action given.\n"));
193 g_printerr(_("Run %s --help for command-line options.\n"), app
.programname
);
197 conf_write(&conf
, app
.conf_dir
);