summaryrefslogtreecommitdiff
path: root/src/_logic.c
blob: 5e29d5499412d0b2e1e2142bd2991c89fc463576 (plain)
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
169
170
171
172
173
174
175
 /*
  * Copyright 2012  Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.0 (the License);
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.tizenopensource.org/license
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an AS IS BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */

#include <Ecore_X.h>
#include <heynoti.h>

#include "crash-worker-sdk.h"
#include "_util_log.h"
#include "_util_efl.h"


static void _response_cb(void *data, Evas_Object *obj, void *event_info)
{
	struct appdata *ad = (struct appdata *)data;
	evas_object_hide(ad->win);
	evas_object_del(ad->win);
	ad->win = NULL;
}

static void _close_response_cb(void *data, Evas_Object *obj, void *event_info)
{
	struct appdata *ad = (struct appdata *)data;
	retm_if(ad == NULL, "Invalid argument:appdata is NULL\n");

	_D("wait timer stopped\n");
	if (ad->et) {
		ecore_timer_del(ad->et);
		ad->et = NULL;
	}
	if (ad->win) {
		evas_object_del(ad->win);
		ad->win = NULL;
	}
}

void _add_sorry_popup(struct appdata *ad)
{
	Evas_Object *pu, *bt1;
	char buf[512] = {0, };

	snprintf(buf, sizeof(buf), "%s %s",
			ad->file, "has stopped unexpectedly.");
	pu = elm_popup_add(ad->win);

	elm_object_part_text_set(pu, "title,text", "Sorry!");
	elm_object_text_set(pu, buf);

	bt1 = elm_button_add(pu);
	elm_object_text_set(bt1, "Close");
	elm_object_part_content_set(pu, "button1", bt1);
	evas_object_smart_callback_add(bt1, "clicked",_close_response_cb, ad);

	evas_object_show(pu);
}

Eina_Bool _wait_timer_cb(void *data)
{
	struct appdata *ad = (struct appdata *)data;
	retvm_if(ad == NULL, 0, "Invalid argument: appdata is NULL\n");

	_D("wait time started, so thread triggered.\n");
	if (ad->win) {
		evas_object_del(ad->win);
		ad->win = NULL;
	}
	return ECORE_CALLBACK_CANCEL;
}

int _app_create(struct appdata *ad)
{
	int ret, val;
	double scale;
	int state = 0;
	char buf[64] = {0, };
	Evas_Object *win;
	Evas_Coord w, h;
	Ecore_X_Atom effect_state_atom;
	retvm_if(ad == NULL, -1, "Invalid argument: appdata is NULL\n");

	win = _add_window(PACKAGE, &w, &h);
	retvm_if(win == NULL, -1, "Failed to create window\n");
	elm_win_alpha_set(win, EINA_TRUE);
	evas_object_show(win);
	ad->win = win;

	scale = w / 720.0;
	elm_config_scale_set(scale);
	_D("scale(%lf)\n", scale);

	elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);

	/* disable window effect */
	effect_state_atom = ecore_x_atom_get("_NET_CM_WINDOW_EFFECT_ENABLE");
	_D("window effect is (%d)\n", effect_state_atom);
	ecore_x_window_prop_property_set(elm_win_xwindow_get(win),
			effect_state_atom, ECORE_X_ATOM_CARDINAL, 32, &state, 1);

	_add_sorry_popup(ad);
	if (ad->et) {
		ecore_timer_del(ad->et);
		ad->et = NULL;
	}
	ad->et = ecore_timer_add(10.0, _wait_timer_cb, ad);

	return 0;
}

int _main(int argc, char *argv[], struct appdata *ad)
{
	int i;
	int len, tlen, plen;
	char *file, *path;
	char *name, *pid, *time;

	_D("argc(%d)\n", argc);
	for (i = 0; i < argc; i++) {
		_D("%s\n", argv[i]);
	}

	path = (char *)ecore_file_dir_get(argv[1]);
	retvm_if(path == NULL, -1, "Failed to get cs path\n");
	snprintf(ad->cspath, sizeof(ad->cspath), "%s", path);
	if (path)	free(path);

	file = (char *)ecore_file_file_get(argv[1]);
	retvm_if(file == NULL, -1, "Failed to get file name\n");
	len = strlen(file);
	snprintf(ad->csname, len - strlen(".cs") + 1, "%s", file);

	tlen = len - strlen("yyyymmddhhmmss") - strlen(".cs");
	time = &file[tlen];

	pid = time - 2;
	tlen -= 2;
	while (*pid != '_' && tlen > 0) {
		pid--;
		tlen--;
	}
	retvm_if(tlen <= 0, -1, "Failed to get file name (%s)\n", argv[1]);
	plen = strlen(pid);
	snprintf(ad->file, len - plen + 1, "%s", file);
	ad->file[len - plen + 2] = '\0';
	_D("file(%s)\n", ad->file);

	return 0;
}

int _app_terminate(struct appdata *ad)
{
	char buf[256] = {0, };
	if (ad->fd) {
		heynoti_close(ad->fd);
		ad->fd = 0;
	}

	snprintf(buf, sizeof(buf), "%s/%s.%s", ad->cspath, ad->csname, "compressing");
	remove(buf);
	heynoti_publish(CRASH_VIEWER_UPDATE);

	return 0;
}