~ubuntu-branches/ubuntu/maverick/notecase/maverick

« back to all changes in this revision

Viewing changes to src/_unx/SingleInstance.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2005-09-09 09:32:43 UTC
  • Revision ID: james.westby@ubuntu.com-20050909093243-s6namw0yh7q3tqy0
Tags: upstream-1.0.5
ImportĀ upstreamĀ versionĀ 1.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////
 
2
// NoteCase notes manager project <http://notecase.sf.net>
 
3
//
 
4
// This code is licensed under BSD license.See "license.txt" for more details.
 
5
//
 
6
// File: object of this class should be alive as long as program lives
 
7
//               so that instance can be detected (borowed from gnome-volume-manager)
 
8
////////////////////////////////////////////////////////////////////////////
 
9
/*
 
10
 * src/clipboard.c - X clipboard hack to detect if daemon is running
 
11
 *
 
12
 * Elliot Lee <sopwith@redhat.com>
 
13
 *
 
14
 * (C) Copyright 1999 Red Hat, Inc.
 
15
 *
 
16
 * Licensed under the GNU GPL v2.  See COPYING.
 
17
 */
 
18
 
 
19
#include "SingleInstance.h"
 
20
#include <errno.h>
 
21
#include <gtk/gtk.h>
 
22
#include <gdk/gdkx.h>
 
23
 
 
24
//pair of dummy functions
 
25
static void clipboard_get_func (GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, gpointer user_data_or_owner){}
 
26
static void clipboard_clear_func (GtkClipboard *clipboard, gpointer user_data_or_owner){}
 
27
 
 
28
#define CLIPBOARD_NAME "_NOTECASE"
 
29
 
 
30
/*
 
31
 * notecase_get_clipboard - try and get the CLIPBOARD_NAME clipboard
 
32
 *
 
33
 * Returns TRUE if successfully retrieved and FALSE otherwise.
 
34
 */
 
35
gboolean notecase_get_clipboard ()
 
36
{
 
37
        return 1;
 
38
        static const GtkTargetEntry targets[] = { {CLIPBOARD_NAME, 0, 0} };
 
39
        Atom atom = gdk_x11_get_xatom_by_name (CLIPBOARD_NAME);
 
40
        gboolean retval = FALSE;
 
41
        GtkClipboard *clipboard;
 
42
 
 
43
        XGrabServer (GDK_DISPLAY ());
 
44
 
 
45
        if (XGetSelectionOwner (GDK_DISPLAY (), atom) != None)
 
46
                goto out;
 
47
 
 
48
        clipboard = gtk_clipboard_get (gdk_atom_intern (CLIPBOARD_NAME, FALSE));
 
49
 
 
50
        if (gtk_clipboard_set_with_data (clipboard, targets,
 
51
                                         G_N_ELEMENTS (targets),
 
52
                                         clipboard_get_func,
 
53
                                         clipboard_clear_func, NULL))
 
54
                retval = TRUE;
 
55
 
 
56
out:
 
57
        XUngrabServer (GDK_DISPLAY ());
 
58
        gdk_flush ();
 
59
 
 
60
        return retval;
 
61
}
 
62
 
 
63
CSingleInstance::CSingleInstance(const char *szName)
 
64
{
 
65
        m_bAlreadyExists = !notecase_get_clipboard();
 
66
}
 
67
 
 
68
CSingleInstance::~CSingleInstance()
 
69
{
 
70
}
 
71
 
 
72
bool CSingleInstance::ProgramAlreadyStarted()
 
73
{
 
74
        return m_bAlreadyExists;
 
75
}
 
76
 
 
77