~nochka85/cairo-dock-plug-ins/quick_rss_reader

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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/bin/bash

# This is a part of the external applet quick_rss_reader.py for Cairo-Dock
#
# Copyright : (C) 2009 by Yann Dulieu (Nochka85)
# E-mail : nochka85@cairo-dock.org
#
#
# 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.
# http://www.gnu.org/licenses/licenses.html#GPL
#
#
# Rev : 0.0.4
# Date : 09/09/20

APP_FOLDER=$(pwd)

DBUS_NAME="org.cairodock.CairoDock"
DBUS_PATH="/org/cairodock/CairoDock"
DBUS_INTERFACE="org.cairodock.CairoDock"
COMMAND=$0
SCRIPT_NAME=`basename $COMMAND`
APP_NAME="`echo $SCRIPT_NAME | cut -f1 -d '.' `"
ACTION=$1
DROP_DATA=$2
MENU_SELECT=$2
SCROLL_UP=$2
CURRENT_FEED="1"

CONF_FILE="/home/$USER/.config/cairo-dock/current_theme/plug-ins/$APP_NAME/$APP_NAME.conf"
TEMP_FILE_PATH="/tmp"
TEMP_FILE_NAME="cd-$APP_NAME"

DESCRIPTION="This applet allows you to simply read RSS feeds.
Usage :
Scroll UP/DOWN = switch between the rss feeds.
Left click = Display the current rss feed infos in an info-bubble.
Middle click = Display the current rss feed name.
'Open this rss feed' in menu = Open the current rss feed in your web browser."
AUTHOR="Yann Dulieu (Nochka85)
(contact : nochka85@cairo-dock.org)"
CATEGORY="2"


#############################################################################################################
register_the_applet() {
dbus-send --session --dest=$DBUS_NAME $DBUS_PATH $DBUS_INTERFACE.RegisterNewModule string:"$APP_NAME" string:"$DESCRIPTION" string:"$AUTHOR" int32:$CATEGORY string:"$APP_FOLDER"
exit
}

#############################################################################################################
get_conf_param() {
LIGNE=`cat $CONF_FILE | grep "$1"`
PARAM="`echo $LIGNE | cut -f2 -d '=' `"
}

#############################################################################################################
get_temp_file_info() {
LIGNE=`cat "$TEMP_FILE_PATH/$TEMP_FILE_NAME" | grep "$1"`
PARAM="`echo $LIGNE | cut -f2 -d '=' `"
}

#############################################################################################################
get_common_conf_params() {

get_conf_param "specific_web_browser"
specific_web_browser="$PARAM"
get_conf_param "specific_rss_reader_full_path"
specific_rss_reader_full_path="$PARAM"
get_conf_param "dialogs_duration"
dialogs_duration="$PARAM"

}

#############################################################################################################
display_rss_feed() {

NAME="$1"
URL="$2"
LINES="$3"
TITLE_NUM="$4"
TIME="$5"
USER_RSS_READER_FULL_PATH="$6"

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> $NAME"
echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> $URL"
echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> $LINES"
echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> $TITLE_NUM"
echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> $TIME"
echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> $USER_RSS_READER_FULL_PATH"

if [ "`echo $URL`" == "" ]; then 	# no defined URL
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> NO URL DEFINED FOR THIS ACTION -> No action !"
else
	if [ "`echo $USER_RSS_READER_PATH`" == "" ]; then 	# no specific user rss reader defined
		echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> NO USER RSS READER SCRIPT -> Use the default one !"
		READER_TO_USE="$APP_FOLDER/rss_reader.sh"
	else
		echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> SPECIFIC USER RSS READER DEFINED -> $USER_RSS_READER_FULL_PATH"
		# We test that the script exists :
		USER_READER_NAME="`basename $USER_RSS_READER_FULL_PATH`"
		USER_READER_DIR="`echo "$USER_RSS_READER_FULL_PATH" | sed -e "s/[^\/]*$//"`"
		if [ "`ls "$USER_READER_DIR" | grep "$USER_READER_NAME"`" = "$USER_READER_NAME" ]; then	# the script exists
			READER_TO_USE="$USER_RSS_READER_FULL_PATH"
			echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> THE SCRIPT EXISTS !"
		else
			echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> THE SCRIPT DOESN'T EXIST !"
			exit
		fi
	fi
OUTPUT="`echo "$NAME" && $READER_TO_USE $URL $LINES $TITLE_NUM`"
dbus-send --session --dest=$DBUS_NAME $DBUS_PATH/$APP_NAME $DBUS_INTERFACE.applet.ShowDialog string:"$OUTPUT" int32:$TIME

fi

}

#############################################################################################################
action_on_click() {
get_common_conf_params
get_temp_file_info "CURRENT_FEED"
CURRENT_FEED="$PARAM"

if [ $CURRENT_FEED -eq "1" ]; then
	TEMP_CURRENT_FEED="01"
else
	TEMP_CURRENT_FEED="$CURRENT_FEED"
fi

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Left clic !"

get_conf_param "url_rss_feed_$TEMP_CURRENT_FEED"
url_rss_feed="$PARAM"

get_conf_param "name_rss_feed_$TEMP_CURRENT_FEED"
name_rss_feed="$PARAM"

get_conf_param "lines_rss_feed_$TEMP_CURRENT_FEED"
lines_rss_feed="$PARAM"

get_conf_param "title_num_rss_feed_$TEMP_CURRENT_FEED"
title_num_rss_feed="$PARAM"

display_rss_feed "$name_rss_feed" "$url_rss_feed" "$lines_rss_feed" "$title_num_rss_feed" "$dialogs_duration" "$specific_rss_reader_full_path"

exit
}

#############################################################################################################
action_on_middle_click() {
get_common_conf_params
get_temp_file_info "CURRENT_FEED"
CURRENT_FEED="$PARAM"

if [ $CURRENT_FEED -eq "1" ]; then
	TEMP_CURRENT_FEED="01"
else
	TEMP_CURRENT_FEED="$CURRENT_FEED"
fi

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Middle clic !"

get_conf_param "name_rss_feed_$TEMP_CURRENT_FEED"
name_rss_feed="$PARAM"

dbus-send --session --dest=$DBUS_NAME $DBUS_PATH/$APP_NAME $DBUS_INTERFACE.applet.ShowDialog string:"$name_rss_feed" int32:2
dbus-send --session --dest=$DBUS_NAME $DBUS_PATH/$APP_NAME $DBUS_INTERFACE.applet.Animate string:default int32:2

exit
}

#############################################################################################################
action_on_scroll_icon() {

if [ "`echo $SKIP`" != "YES" ]; then
	get_temp_file_info "CURRENT_FEED"
	CURRENT_FEED="$PARAM"
fi

if [ $SCROLL_UP -eq "0" ]; then
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Scroll UP !"
	CURRENT_FEED=$((CURRENT_FEED + 1))

	if [ $CURRENT_FEED -eq "11" ]; then
		CURRENT_FEED=1
	fi

	if [ $CURRENT_FEED -eq "1" ]; then
		TEMP_CURRENT_FEED="01"
	else
		TEMP_CURRENT_FEED="$CURRENT_FEED"
	fi
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Current feed = $CURRENT_FEED"

	get_conf_param "url_rss_feed_$TEMP_CURRENT_FEED"
	url_rss_feed="$PARAM"

	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> URL = $url_rss_feed"

	get_conf_param "url_rss_feed_$TEMP_CURRENT_FEED"
	url_rss_feed="$PARAM"

	LAST_SCROLL="0"

else
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Scroll DOWN !"
	CURRENT_FEED=$((CURRENT_FEED - 1))

	if [ $CURRENT_FEED -eq "0" ]; then
		CURRENT_FEED=10
	fi

	if [ $CURRENT_FEED -eq "1" ]; then
		TEMP_CURRENT_FEED="01"
	else
		TEMP_CURRENT_FEED="$CURRENT_FEED"
	fi
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Current feed = $CURRENT_FEED"

	get_conf_param "url_rss_feed_$TEMP_CURRENT_FEED"
	url_rss_feed="$PARAM"

	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> URL = $url_rss_feed"


	get_conf_param "url_rss_feed_$TEMP_CURRENT_FEED"
	url_rss_feed="$PARAM"
	
	LAST_SCROLL="1"

fi

echo "CURRENT_FEED=$CURRENT_FEED" > $TEMP_FILE_PATH/$TEMP_FILE_NAME   # writing temp file to retrieve informations

if [ "`echo $url_rss_feed`" == "" ]; then
	SKIP="YES"
	if [ "`echo $LAST_SCROLL`" == "0" ]; then
		SCROLL_UP="0"
		action_on_scroll_icon
	else
		SCROLL_UP="1"
		action_on_scroll_icon
	fi
else
	SKIP="NO"
	get_conf_param "name_rss_feed_$TEMP_CURRENT_FEED"
	name_rss_feed="$PARAM"
	if [ "`echo $name_rss_feed`" == "" ]; then
		name_rss_feed="(no name defined)"
	fi
fi

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> NAME = $name_rss_feed"

dbus-send --session --dest=$DBUS_NAME $DBUS_PATH/$APP_NAME $DBUS_INTERFACE.applet.ShowDialog string:"$name_rss_feed" int32:1
dbus-send --session --dest=$DBUS_NAME $DBUS_PATH/$APP_NAME $DBUS_INTERFACE.applet.Animate string:default int32:2

exit
}

#############################################################################################################
action_on_drop_data() {
get_common_conf_params

if [ "`echo $DROP_DATA |grep 'file://'`" != "" ]; then 	# It's a file !
	DROP_DATA="`echo $DROP_DATA | cut -c 8-`"  # we remove 'file://' before the location
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> FILE : $DROP_DATA has been dropped on applet : No specific action defined for dropped files !"
else	# It's an URL ! -> we keep the 'http://' in the name
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> URL : $DROP_DATA has been dropped on applet : No specific action defined for dropped url !" 
fi
exit
}

#############################################################################################################
action_on_init() {
get_common_conf_params

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Our module init -> DONE !"
rm -f $TEMP_FILE_PATH/$TEMP_FILE_NAME
echo "CURRENT_FEED=1" > $TEMP_FILE_PATH/$TEMP_FILE_NAME   # writing temp file to retrieve informations

exit
}

#############################################################################################################
action_on_stop() {
get_common_conf_params

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Our module is stopped"
rm -f $TEMP_FILE_PATH/$TEMP_FILE_NAME

exit
}

#############################################################################################################
action_on_reload() {
get_common_conf_params

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Our module is reloaded"
rm -f $TEMP_FILE_PATH/$TEMP_FILE_NAME
echo "CURRENT_FEED=1" > $TEMP_FILE_PATH/$TEMP_FILE_NAME   # writing temp file to retrieve informations

exit
}

#############################################################################################################
action_on_build_menu() {
get_common_conf_params

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Build menu !"
dbus-send --session --dest=$DBUS_NAME $DBUS_PATH/$APP_NAME $DBUS_INTERFACE.applet.PopulateMenu array:string:"Open this rss feed"

exit
}

#############################################################################################################
action_on_menu_select() {
get_common_conf_params
get_temp_file_info "CURRENT_FEED"
CURRENT_FEED="$PARAM"

if [ $CURRENT_FEED -eq "1" ]; then
	TEMP_CURRENT_FEED="01"
else
	TEMP_CURRENT_FEED="$CURRENT_FEED"
fi

echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Choice $MENU_SELECT has been selected !"

get_conf_param "url_rss_feed_$TEMP_CURRENT_FEED"
url_rss_feed="$PARAM"


if [ "`echo $specific_web_browser`" == "" ]; then
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> No browser defined -> Use firefox !"
	firefox $url_rss_feed > /dev/null 2>&1 &
	exit
else
	echo "$APP_NAME applet -> Script Name : $SCRIPT_NAME -> Specific web browser defined in conf : $specific_web_browser"
	$specific_web_browser $url_rss_feed > /dev/null 2>&1 &
fi

exit
}

#############################################################################################################
# START ### DO NOT CHANGE THIS SECTION
#############################################################################################################

if [ "`echo $ACTION |grep 'register_the_applet'`" != "" ]; then
	register_the_applet
elif [ "`echo $ACTION |grep 'action_on_click'`" != "" ]; then
	action_on_click
elif [ "`echo $ACTION |grep 'action_on_middle_click'`" != "" ]; then
	action_on_middle_click
elif [ "`echo $ACTION |grep 'action_on_scroll_icon'`" != "" ]; then
	action_on_scroll_icon
elif [ "`echo $ACTION |grep 'action_on_drop_data'`" != "" ]; then
	action_on_drop_data
elif [ "`echo $ACTION |grep 'action_on_init'`" != "" ]; then
	action_on_init
elif [ "`echo $ACTION |grep 'action_on_stop'`" != "" ]; then
	action_on_stop
elif [ "`echo $ACTION |grep 'action_on_reload'`" != "" ]; then
	action_on_reload
elif [ "`echo $ACTION |grep 'action_on_build_menu'`" != "" ]; then
	action_on_build_menu
elif [ "`echo $ACTION |grep 'action_on_menu_select'`" != "" ]; then
	action_on_menu_select
fi

exit