File: wulformanager.hh

package info (click to toggle)
linuxdcpp 0.0.1.cvs20061024-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,928 kB
  • ctags: 4,932
  • sloc: cpp: 30,399; ansic: 434; makefile: 134
file content (106 lines) | stat: -rw-r--r-- 3,400 bytes parent folder | download
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
/* 
 * Copyright © 2004-2006 Jens Oknelid, paskharen@gmail.com
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef WULFOR_MANAGER_HH
#define WULFOR_MANAGER_HH

#include <gtk/gtk.h>
#include <pthread.h>
#include <semaphore.h>
#include <string>

#include "bookentry.hh"
#include "dialogentry.hh"
#include "mainwindow.hh"

class WulforManager
{
	public:
		static void start();
		static void stop();
		static WulforManager *get();

		WulforManager();
		~WulforManager();

		std::string getPath();
		MainWindow *getMainWindow();
		void dispatchGuiFunc(FuncBase *func);
		void dispatchClientFunc(FuncBase *func);

		// BookEntry functions
		BookEntry *addPublicHubs_gui();
		BookEntry *addHub_gui(std::string address, std::string nick="", std::string desc="", std::string password="");
		BookEntry *addPrivMsg_gui(User::Ptr user, bool raise = TRUE);
		BookEntry *addDownloadQueue_gui();
		BookEntry *addFavoriteHubs_gui();
		BookEntry *addSearch_gui();
		BookEntry *addShareBrowser_gui(User::Ptr user, std::string file, bool raise = TRUE);
		BookEntry *addFinishedTransfers_gui(std::string title);
		void deleteBookEntry_gui(BookEntry *entry);

		// DialogEntry functions
		int openHashDialog_gui();
		int openSettingsDialog_gui();

	private:
		// MainWindow-related functions
		void createMainWindow();
		void deleteMainWindow();

		// BookEntry functions
		BookEntry *getBookEntry_gui(std::string id, bool raise = TRUE);
		void insertBookEntry_gui(BookEntry *entry, bool raise = TRUE);
		void deleteAllBookEntries();

		// DialogEntry functions
		DialogEntry *getDialogEntry_gui(std::string id);
		void insertDialogEntry_gui(DialogEntry *entry);
		void hideDialogEntry_gui(DialogEntry *entry);
		void deleteDialogEntry_gui(DialogEntry *entry);
		void deleteAllDialogEntries();

		// Thread-related functions
		static void *threadFunc_gui(void *data);
		static void *threadFunc_client(void *data);
		void processGuiQueue();
		void processClientQueue();

		// Callbacks
		static gboolean onCloseWindow_gui(GtkWidget *widget, GdkEvent *event, gpointer data);
		static void onCloseBookEntry_gui(GtkWidget *widget, gpointer data);
		static void onCloseDialogEntry_gui(GtkDialog *dialog, gint response, gpointer data);

		static WulforManager *manager;
		MainWindow *mainWin;
		std::string path;
		std::vector<FuncBase *> guiFuncs;
		std::vector<FuncBase *> clientFuncs;
		hash_map<std::string, BookEntry *> bookEntries;
		hash_map<std::string, DialogEntry *> dialogEntries;
		pthread_mutex_t clientCallLock;
		pthread_mutex_t guiQueueLock, clientQueueLock;
		pthread_mutex_t bookEntryLock;
		pthread_mutex_t dialogEntryLock;
		sem_t guiSem, clientSem;
		pthread_t guiThread, clientThread;
};

#else
class WulforManager;
#endif