1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
17 #include <stdlib.h> /* for exit (and __argc and __argv on windows) */
42 if (conf
.spawn_command
== NULL
)
43 conf
.spawn_command
= g_strdup(spawn_commands
[0].command
);
47 conf_verify_a_host_exists();
49 if (conf
.cfuserinterval
== 0)
50 conf
.cfuserinterval
= 30;
51 cf_threshold_normalize(&conf
.cfthreshold
);
56 try_remote_command(JamAccount
*acc
) {
57 const char *username
= acc
? jam_account_get_username(acc
) : NULL
;
59 /* send the remote command.
60 * you'd think we'd want to conditionally do this on the configuration
61 * option, but you'd be wrong. :)
62 * if the setting in the conf is "allow multiple instances", but then
63 * the user changes the setting to "only one instance" in the ui and then
64 * runs another copy of logjam, it's counterintuitive for it to ignore that
65 * changed ui setting, even if it hadn't got propogated to the
66 * configuration file yet.
67 * so we always try to use the socket. the conf setting is only
68 * used when we consider *creating* the socket. */
70 /* a null username just brings the window to the foreground. */
71 if (remote_send_user(username
, &err
)) {
72 /* we popped up another window, so we're done. */
73 g_print(_("Bringing already-running LogJam instance to the "
77 g_printerr(_("Error sending remote command: %s.\n"), err
->message
);
85 init_app(int *argc
, gchar
*argv
[]) {
88 memset(&app
, 0, sizeof(Application
));
89 app
.programname
= argv
[0]; /* not the same as PROGRAMNAME */
91 /* treatment of configuration dir; must be done before read_conf */
92 for (i
= 1; i
< *argc
; i
++) { /* look for arg */
93 if (!strcmp(argv
[i
], "--conf-dir")) {
94 app
.conf_dir
= argv
[i
+1];
98 if (g_strrstr(argv
[i
], "--conf-dir=")) {
99 app
.conf_dir
= argv
[i
] + strlen("--conf-dir=");
104 if (shift
) { /* shift what comes after */
106 for (; i
< *argc
; i
++) {
107 argv
[i
] = argv
[i
+ shift
];
112 app
.conf_dir
= g_strdup_printf("%s/.logjam", g_get_home_dir());
115 app
.tooltips
= gtk_tooltips_new();
116 gtk_tooltips_enable(app
.tooltips
);
122 run_gtk(JamDoc
*doc
) {
125 app
.remote
= logjam_remote_new();
127 accelpath
= g_build_filename(app
.conf_dir
, "accels", NULL
);
128 gtk_accel_map_load(accelpath
);
132 /* the 99% common case is the user has a username/password/host remembered
133 * and they just want to use those. */
134 if (!jam_doc_get_account(doc
)) {
135 JamAccount
*acc
= NULL
;
136 if (conf
.lasthost
&& conf
.lasthost
->lastaccount
&&
137 conf
.lasthost
->lastaccount
->remember_password
) {
138 acc
= conf
.lasthost
->lastaccount
;
139 if (JAM_ACCOUNT_IS_LJ(acc
))
140 login_check_lastupdate(NULL
, JAM_ACCOUNT_LJ(acc
));
142 acc
= login_dlg_run(NULL
, conf
.lasthost
, acc
);
146 jam_doc_set_account(doc
, acc
);
151 g_object_unref(G_OBJECT(app
.remote
));
153 gtk_accel_map_save(accelpath
);
161 /* This call actually initializes the locale settings,
162 * and doesn't just clear LC_ALL (which is sorta what
163 * it looks like it's doing). */
164 setlocale(LC_ALL
, "");
167 bindtextdomain(GETTEXT_PACKAGE
, LOCALEDIR
);
168 /* GTK always wants UTF-8 strings.
169 * gettext will try to translate to the current locale's codeset
170 * unless we tell it to leave it in UTF-8. */
171 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8");
172 textdomain(GETTEXT_PACKAGE
);
179 /* calls to these thread inits must happen before any other
181 if (!g_thread_supported()) g_thread_init(NULL
);
184 #endif /* HAVE_GTK */
188 g_set_application_name(_("LogJam"));
192 main(int argc
, char* argv
[]) {
202 init_app(&argc
, argv
); /* should be called before conf_read */
203 conf_read(&conf
, app
.conf_dir
);
205 jam_account_logjam_init();
209 gtk_rc_add_default_file("gtkrc");
211 has_gtk
= gtk_init_check(&argc
, &argv
);
215 cmdline_parse(doc
, argc
, argv
); /* may terminate. */
219 g_printerr(_("GTK init failed -- are you in X?\n"));
220 g_printerr(_("Run %s --help for command-line options.\n"), app
.programname
);
223 try_remote_command(jam_doc_get_account(doc
));
226 g_printerr(_("Error: No action given.\n"));
227 g_printerr(_("Run %s --help for command-line options.\n"), app
.programname
);
231 conf_write(&conf
, app
.conf_dir
);
241 int _stdcall
WinMain(void *hInst
, void *hPrev
, char* lpCmdLine
, int nCmdShow
) {
242 return main(__argc
, __argv
);