Statistics
| Revision:

root / trunk / client / gui / ipc_osx.c @ 1857

History | View | Annotate | Download (3.1 KB)

1
/* 
2
    Copyright (C) 2005-2010  Erik van Pienbroek
3

                
4
    This program is free software; you can redistribute it and/or modify
5
    it under the terms of the GNU General Public License as published by
6
    the Free Software Foundation; either version 2 of the License, or
7
    (at your option) any later version.
8

                
9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU General Public License for more details.
13

                
14
    You should have received a copy of the GNU General Public License
15
    along with this program; if not, write to the Free Software
16
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
*/
18

                
19
#include 
20
#include "gui.h"
21

                
22
static gboolean
23
open_nzb_cb(gpointer data)
24
{
25
    char *path = data;
26

                
27
    if (!gui_get_is_initialized()) {
28
        return TRUE;   /* Try again later */
29
    }
30

                
31
    do_open_nzb_file(path);
32
    g_free(path);
33
    return FALSE;
34
}
35

                
36
static pascal OSErr openFilesHandle(const AppleEvent *inAppleEvent, AppleEvent *ioAppleEvent, long inHandlerRefcon)
37
{
38
    AEDescList documentsList;
39
    OSErr err = AEGetParamDesc(inAppleEvent, keyDirectObject, typeAEList, &documentsList);
40
    require_noerr(err, error);
41

                
42
    long first;
43
    OSStatus result = AECountItems(&documentsList, &first);
44
    require_noerr(result, error);
45

                
46
#if 0 
47
    int idx, cnt = first;
48
    for (idx = 1; idx <= cnt; idx++) {
49
#endif
50
    int idx = 1;
51

                
52
        FSRef tFSRef;
53

                
54
        result = AEGetNthPtr(&documentsList, idx, typeFSRef, NULL,NULL, &tFSRef, sizeof(FSRef), NULL);
55

                
56
        unsigned char path[1024];
57
        memset(&path, 0, sizeof(path));
58
        FSRefMakePath(&tFSRef, path, sizeof(path));
59

                
60
        if (gui_get_is_initialized()) {
61
            do_open_nzb_file((char*) path);
62
        } else {
63
            /* Try again later */
64
#if GLIB_CHECK_VERSION(2,14,0)
65
            g_timeout_add_seconds(1, open_nzb_cb, g_strdup((char*) path));
66
#else
67
            g_timeout_add(1000, open_nzb_cb, g_strdup((char*) path));
68
#endif
69
        }
70
#if 0 
71
    }
72
#endif
73

                
74
    AEDisposeDesc(&documentsList);
75

                
76
error:
77
    return err;
78
}
79

                
80
gboolean
81
ipc_test_is_nntpgrab_already_running(gboolean also_check_server)
82
{
83
    // No implementation required for OSX
84

                
85
    if (!also_check_server) {
86
        return FALSE;
87
    }
88

                
89
    // Is the nntpgrab server running?
90
    if (glue && nntpgrab_glue_get_is_standalone(glue) && nntpgrab_utils_test_is_server_already_running()) {
91
        nntpgrab_gui_base_dialog_show(nntpgrab_gui_base_get_widget("windowMain"), _("The NNTPGrab Server is already running.\nThis program and the NNTPGrab Server cannot run at the same time"), GTK_MESSAGE_WARNING, GTK_BUTTONS_OK);
92
        return TRUE;
93
    }
94

                
95
    return FALSE;
96
}
97

                
98
gboolean
99
ipc_initialize(void)
100
{
101
    AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, openFilesHandle, 0, FALSE);
102

                
103
    if (ipc_test_is_nntpgrab_already_running(TRUE)) {
104
        return FALSE;
105
    }
106

                
107
    return TRUE;
108
}
109

                
110
void
111
ipc_cleanup(void)
112
{
113
}
114

                
115
void
116
ipc_send_open_nzb_file_request(const char *nzb_file)
117
{
118
    // No implementation required for OSX
119
}