forked from DC-SWAT/DreamShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.h
More file actions
168 lines (141 loc) · 3.57 KB
/
Copy pathapp.h
File metadata and controls
168 lines (141 loc) · 3.57 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* \file app.h
* \brief DreamShell applications
* \date 2007-2014
* \author SWAT www.dc-swat.ru
*/
#ifndef _DS_APP_H
#define _DS_APP_H
#include <kos.h>
#include "list.h"
#include "gui.h"
#include "mxml.h"
#include "console.h"
#include "lua.h"
/**
* App state flags
*/
#define APP_STATE_OPENED 0x00000001
#define APP_STATE_LOADED 0x00000002
#define APP_STATE_READY 0x00000004
#define APP_STATE_PROCESS 0x00000008
#define APP_STATE_SLEEP 0x00000020
#define APP_STATE_WAIT_UNLOAD 0x00000040
/**
* App info structure
*/
typedef struct App {
const char fn[MAX_FN_LEN];
const char icon[MAX_FN_LEN];
const char name[64];
const char ver[32];
const char ext[64];
const char *args;
uint32 id;
uint32 state;
Item_list_t *resources;
Item_list_t *elements;
mxml_node_t *xml;
kthread_t *thd;
lua_State *lua;
GUI_Widget *body;
} App_t;
/**
* Initialize and shutdown application system
*/
int InitApps();
void ShutdownApps();
/**
* Apps list utils
*/
Item_list_t *GetAppList();
App_t *GetAppById(int id);
App_t *GetAppByFileName(const char *fn);
App_t *GetAppByName(const char *name);
App_t *GetAppByExtension(const char *ext);
App_t *GetAppsByExtension(const char *ext, App_t **app_list, size_t count);
/**
* Get current opened application
*/
App_t *GetCurApp();
/**
* Parse app XML file and add to list
*
* return NULL on error
*/
App_t *AddApp(const char *fn);
/**
* Remove app from list
*/
int RemoveApp(App_t *app);
/**
* Open app with arguments (if needed)
* Application can be loaded and builded automatically
*
* return 0 on error and 1 on success
*/
int OpenApp(App_t *app, const char *args);
/**
* Close app and unload (if unload > 0)
*
* return 0 on error and 1 on success
*/
int CloseApp(App_t *app, int unload);
/**
* Loading and unloading app resources
*
* return 0 on error and 1 on success
*/
int LoadApp(App_t *app, int build);
int UnLoadApp(App_t *app);
/**
* Building app body from XML tree
*
* return 0 on error and 1 on success
*/
int BuildAppBody(App_t *app);
/**
* Add and remove GUI widget to/from app body Panel widget
*
* return 0 on error and 1 on success
*/
int AddToAppBody(App_t *app, GUI_Widget *widget);
int RemoveFromAppBody(App_t *app, GUI_Widget *widget);
/**
* Calling app exported function
*
* return 0 on error and 1 on success
*/
int CallAppExportFunc(App_t *app, const char *fstr);
/**
* Calling app onload, onunload, onopen and onclose events
*
* return 0 on error and 1 on success
*/
int CallAppBodyEvent(App_t *app, char *event);
/**
* Waiting for clear flag APP_STATE_PROCESS
*/
void WaitApp(App_t *app);
/**
* Setup APP_STATE_SLEEP flag manualy
*
* return 0 on error and 1 on success
*/
int SetAppSleep(App_t *app, int sleep);
/**
* Check extension supported
*
* return 0 is NOT and 1 on success
*/
int IsFileSupportedByApp(App_t *app, const char *filename);
/* Utils */
char *FindXmlAttr(char *name, mxml_node_t *node, char *defValue);
void UnLoadOldApps();
void UnloadAppResources(Item_list_t *lst);
/* Resource helpers */
void *getAppElement(App_t *app, const char *name, ListItemType type);
#define APP_GET_WIDGET(name) ((GUI_Widget *) getAppElement(self.app, name, LIST_ITEM_GUI_WIDGET))
#define APP_GET_SURFACE(name) ((GUI_Surface *) getAppElement(self.app, name, LIST_ITEM_GUI_SURFACE))
#define APP_GET_FONT(name) ((GUI_Font *) getAppElement(self.app, name, LIST_ITEM_GUI_FONT))
#endif