| tvkaista-0.964/tvkaista-helper.pl | | tvkaista-0.971/tvkaista-helper.pl |
| 4 | # Author: Tomi Ollila -- too ät iki piste fi | 4 | # Author: Tomi Ollila -- too ät iki piste fi |
| 5 | # | 5 | # |
| 6 | # Created: Sat Feb 07 21:29:53 EET 2009 too | 6 | # Created: Sat Feb 07 21:29:53 EET 2009 too |
| 7 | # Last modified: Mon 04 May 2009 21:40:38 EEST too | 7 | # Last modified: Thu 07 May 2009 23:26:25 EEST too |
| 8 | | 8 | |
| 9 | #PERL_UNICODE=SD perl tvkaista-helper.pl 1 update | 9 | #PERL_UNICODE=SD perl tvkaista-helper.pl 1 update |
| 10 | #or perl -CSD perl tvkaista-helper.pl 1 list | 10 | #or perl -CSD perl tvkaista-helper.pl 1 list |
| 22 | die "Unicode settings not OK\n" unless (${^UNICODE} & 0x1f) == 0x1f; | 22 | die "Unicode settings not OK\n" unless (${^UNICODE} & 0x1f) == 0x1f; |
| 23 | | 23 | |
| 24 | die "Cache directory missing. probably incomplete installation\n" | 24 | die "Cache directory missing. probably incomplete installation\n" |
| 25 | unless -d 2; | 25 | unless -d 3; |
| 26 | | 26 | |
| 27 | sub usage() | 27 | sub usage() |
| 28 | { | 28 | { |
| 49 | } | 49 | } |
| 50 | getdatetime; | 50 | getdatetime; |
| 51 | | 51 | |
| 52 | unless (-d "2/logs.$date") { | 52 | unless (-d "3/logs.$date") { |
| 53 | mkdir "2/logs.$date"; | 53 | mkdir "3/logs.$date"; |
| 54 | unlink '2/today'; | 54 | unlink '3/today'; |
| 55 | symlink "logs.$date", '2/today'; | 55 | symlink "logs.$date", '3/today'; |
| 56 | } | 56 | } |
| 57 | | 57 | |
| 58 | my ($username, $password, $b64cred) = ('', '', ''); | 58 | my ($username, $password, $b64cred) = ('', '', ''); |
| 87 | print "\n"; | 87 | print "\n"; |
| 88 | system 'stty', 'echo'; | 88 | system 'stty', 'echo'; |
| 89 | } | 89 | } |
| 90 | open O, '>', '2/tunnus' or die $!; | 90 | open O, '>', '3/tunnus' or die $!; |
| 91 | print O "tunnus = $username\nsalasana = $password\n"; | 91 | print O "tunnus = $username\nsalasana = $password\n"; |
| 92 | close O; | 92 | close O; |
| 93 | $b64cred = encode_base64 "$username:$password", ''; | 93 | $b64cred = encode_base64 "$username:$password", ''; |
| 144 | my @programs; | 144 | my @programs; |
| 145 | sub fillprograms() | 145 | sub fillprograms() |
| 146 | { | 146 | { |
| 147 | my ($chnl, $title, $secs, $desc, $id) = ('', '', ''); | 147 | my ($chnl, $chnlnr, $title, $secs, $desc, $id) = ('', 0, '', '', '', ''); |
| 148 | while (<I>) { | 148 | while (<I>) { |
| 149 | $title = strdecode $1 if /<title>(.*)<\/title>/; | 149 | $title = strdecode $1 if /<title>(.*)<\/title>/; |
| 150 | $secs = secsof $1 if /<pubDate>(.*)<\/pubDate>/; | 150 | $secs = secsof $1 if /<pubDate>(.*)<\/pubDate>/; |
| 153 | | 153 | |
| 154 | if ( /<ttl>/ ) { | 154 | if ( /<ttl>/ ) { |
| 155 | $desc =~ /channel:\s*(.*)/; | 155 | $desc =~ /channel:\s*(.*)/; |
| 156 | $chnl = $1; $chnl =~ tr/ /_/; | 156 | $chnl = $1; $chnl =~ tr/ /_/; $chnlnr++; # XXX hash instead! |
| 157 | ($title, $secs, $desc, $id) = ('','','',''); | 157 | ($title, $secs, $desc, $id) = ('','','',''); |
| 158 | next; | 158 | next; |
| 159 | } | 159 | } |
| 160 | | 160 | |
| 161 | if ( /<\/item>/ ) { | 161 | if ( /<\/item>/ ) { |
| 162 | push @programs, [ $secs, $chnl, $title, $desc, $id ] if length $id; | 162 | push @programs, [ $secs, $chnlnr, $chnl, $title, $desc, $id ] |
| | 163 | if length $id; |
| 163 | ($title, $secs, $desc, $id) = ('','','',''); | 164 | ($title, $secs, $desc, $id) = ('','','',''); |
| 164 | } | 165 | } |
| 165 | } | 166 | } |
| 167 | | 168 | |
| 168 | sub update () | 169 | sub update () |
| 169 | { | 170 | { |
| 170 | feedwget "2/today/channels-$time.rss", 'http://www.tvkaista.fi/feed/'; | 171 | feedwget "3/today/channels-$time.rss", 'http://www.tvkaista.fi/feed/'; |
| 171 | return 0 if -z "2/today/channels-$time.rss"; | 172 | return 0 if -z "3/today/channels-$time.rss"; |
| 172 | open I, '<', "2/today/channels-$time.rss" or die $!; | 173 | open I, '<', "3/today/channels-$time.rss" or die $!; |
| 173 | my (@channels, $linktail, $c); | 174 | my (@channels, $linktail, $c); |
| 174 | while (<I>) { last if /<ttl>/; } | 175 | while (<I>) { last if /<ttl>/; } |
| 175 | while (<I>) { | 176 | while (<I>) { |
| 184 | push @urls, "http://www.tvkaista.fi/feed/channels/$_/flv.rss" | 185 | push @urls, "http://www.tvkaista.fi/feed/channels/$_/flv.rss" |
| 185 | foreach (@channels); | 186 | foreach (@channels); |
| 186 | | 187 | |
| 187 | feedwget "2/today/a-$time-now.rss", @urls; | 188 | feedwget "3/today/a-$time-now.rss", @urls; |
| 188 | | 189 | |
| 189 | open I, '<', "2/today/a-$time-now.rss" or die $!; | 190 | open I, '<', "3/today/a-$time-now.rss" or die $!; |
| 190 | fillprograms; | 191 | fillprograms; |
| 191 | close I; | 192 | close I; |
| 192 | | 193 | |
| 194 | my @sorted = sort { $a->[0] <=> $b->[0] } @programs; | 195 | my @sorted = sort { $a->[0] <=> $b->[0] } @programs; |
| 195 | @programs = (); | 196 | @programs = (); |
| 196 | my @di = dateinfo $daysecs; | 197 | my @di = dateinfo $daysecs; |
| 197 | my $outputfile = sprintf("2/program_%d-%02d-%02d", | 198 | my $outputfile = sprintf("3/program_%d-%02d-%02d", |
| 198 | $di[4] + 1900, $di[3] + 1, $di[2]); | 199 | $di[4] + 1900, $di[3] + 1, $di[2]); |
| 199 | | 200 | |
| 200 | open O, '>', $outputfile or die $!; | 201 | open O, '>', $outputfile or die $!; |
| 204 | @di = dateinfo $_->[0]; | 205 | @di = dateinfo $_->[0]; |
| 205 | if ($fnd && $di[0] ge "0500") { | 206 | if ($fnd && $di[0] ge "0500") { |
| 206 | close O; | 207 | close O; |
| 207 | open O, '>', sprintf("2/program_%d-%02d-%02d", | 208 | open O, '>', sprintf("3/program_%d-%02d-%02d", |
| 208 | $di[4] + 1900, $di[3] + 1, $di[2]) or die $!; | 209 | $di[4] + 1900, $di[3] + 1, $di[2]) or die $!; |
| 209 | $fnd = 0; | 210 | $fnd = 0; |
| 210 | $pday = ''; | 211 | $pday = ''; |
| 216 | $fnd = 1 if (length $pday); | 217 | $fnd = 1 if (length $pday); |
| 217 | $pday = $di[1]; | 218 | $pday = $di[1]; |
| 218 | } | 219 | } |
| 219 | print O "$_->[4] $di[0] $_->[1] $_->[2]\n"; | 220 | print O "$_->[5] $di[0] $_->[1] $_->[2] $_->[3]\n"; |
| 220 | print O "\\ $_->[3]\n" if length $_->[3]; | 221 | print O "\\ $_->[4]\n" if length $_->[4]; |
| 221 | } | 222 | } |
| 222 | close O; | 223 | close O; |
| 223 | | 224 | |
| 226 | @urls = (); | 227 | @urls = (); |
| 227 | @di = dateinfo $daysecs; $di[4] += 1900; $di[3]++; | 228 | @di = dateinfo $daysecs; $di[4] += 1900; $di[3]++; |
| 228 | | 229 | |
| 229 | $outputfile = sprintf("2/program_%d-%02d-%02d",$di[4],$di[3],$di[2]); | 230 | $outputfile = sprintf("3/program_%d-%02d-%02d",$di[4],$di[3],$di[2]); |
| 230 | my @fst = stat $outputfile; | 231 | my @fst = stat $outputfile; |
| 231 | next if (defined $fst[9] &&$fst[9] > $daysecs); # recent enough. | 232 | next if (defined $fst[9] &&$fst[9] > $daysecs); # recent enough. |
| 232 | | 233 | |
| 234 | . "/channels/$_/flv.rss" foreach (@channels); | 235 | . "/channels/$_/flv.rss" foreach (@channels); |
| 235 | | 236 | |
| 236 | getdatetime; | 237 | getdatetime; |
| 237 | feedwget "2/today/a-$di[3]-$di[2]-$time.rss", @urls; | 238 | feedwget "3/today/a-$di[3]-$di[2]-$time.rss", @urls; |
| 238 | last WHILE unless -s "2/today/a-$di[3]-$di[2]-$time.rss"; | 239 | last WHILE unless -s "3/today/a-$di[3]-$di[2]-$time.rss"; |
| 239 | | 240 | |
| 240 | open I, '<', "2/today/a-$di[3]-$di[2]-$time.rss" or die $!; | 241 | open I, '<', "3/today/a-$di[3]-$di[2]-$time.rss" or die $!; |
| 241 | fillprograms; | 242 | fillprograms; |
| 242 | close I; | 243 | close I; |
| 243 | | 244 | |
| 253 | qw(Su Ma Ti Ke To Pe La)[$di[1]], $di[2], $di[3] + 1; | 254 | qw(Su Ma Ti Ke To Pe La)[$di[1]], $di[2], $di[3] + 1; |
| 254 | $pday = $di[1]; | 255 | $pday = $di[1]; |
| 255 | } | 256 | } |
| 256 | print O "$_->[4] $di[0] $_->[1] $_->[2]\n"; | 257 | print O "$_->[5] $di[0] $_->[1] $_->[2] $_->[3]\n"; |
| 257 | print O "\\ $_->[3]\n" if length $_->[3]; | 258 | print O "\\ $_->[4]\n" if length $_->[4]; |
| 258 | } | 259 | } |
| 259 | close O; | 260 | close O; |
| 260 | } | 261 | } |
| 266 | { | 267 | { |
| 267 | mkpw 1 if ($username eq '' or $password eq ''); | 268 | mkpw 1 if ($username eq '' or $password eq ''); |
| 268 | getdatetime; | 269 | getdatetime; |
| 269 | recwget "2/today/login-$time.html", 'http://www.tvkaista.fi/netpvr/Login', | 270 | recwget "3/today/login-$time.html", 'http://www.tvkaista.fi/netpvr/Login', |
| 270 | '--save-cookies', "2/cookies-$date-$time.txt", '--keep-session-cookies', | 271 | '--save-cookies', "3/cookies-$date-$time.txt", '--keep-session-cookies', |
| 271 | '--max-redirect=0', | 272 | '--max-redirect=0', |
| 272 | '--post-data', | 273 | '--post-data', |
| 273 | "action=login&username=$username&password=$password&rememberme=on"; | 274 | "action=login&username=$username&password=$password&rememberme=on"; |
| 274 | unlink '2/cookies.txt'; | 275 | unlink '3/cookies.txt'; |
| 275 | symlink "cookies-$date-$time.txt", '2/cookies.txt'; | 276 | symlink "cookies-$date-$time.txt", '3/cookies.txt'; |
| 276 | | 277 | |
| 277 | return -z "2/today/login-$time.html"; | 278 | return -z "3/today/login-$time.html"; |
| 278 | } | 279 | } |
| 279 | | 280 | |
| 280 | sub getpw () | 281 | sub getpw () |
| 281 | { | 282 | { |
| 282 | if (-f '2/tunnus') { | 283 | if (-f '3/tunnus') { |
| 283 | open I, '<', '2/tunnus'; | 284 | open I, '<', '3/tunnus'; |
| 284 | while (<I>) { | 285 | while (<I>) { |
| 285 | $username = $1 if /^\s*tunnus\s*=\s*(\S+)/; | 286 | $username = $1 if /^\s*tunnus\s*=\s*(\S+)/; |
| 286 | $password = $1 if /^\s*salasana\s*=\s*(\S+)/; | 287 | $password = $1 if /^\s*salasana\s*=\s*(\S+)/; |
| 301 | my $tof = "$recdir/$_[0].srt"; | 302 | my $tof = "$recdir/$_[0].srt"; |
| 302 | | 303 | |
| 303 | recwget $tof, "http://www.tvkaista.fi/netpvr/Download/$_[0].srt", | 304 | recwget $tof, "http://www.tvkaista.fi/netpvr/Download/$_[0].srt", |
| 304 | '--load-cookies', '2/cookies.txt'; | 305 | '--load-cookies', '3/cookies.txt'; |
| 305 | | 306 | |
| 306 | open I, '<', $tof or return ( $_[0], 0 ); | 307 | open I, '<', $tof or return ( $_[0], 0 ); |
| 307 | | 308 | |
| 329 | | 330 | |
| 330 | getpw; | 331 | getpw; |
| 331 | | 332 | |
| 332 | my $pagename = "2/today/play-$time.html"; | 333 | my $pagename = "3/today/play-$time.html"; |
| 333 | | 334 | |
| 334 | my $format = $speeds{$ARGV[3]}; | 335 | my $format = $speeds{$ARGV[3]}; |
| 335 | recwget $pagename, | 336 | recwget $pagename, |
| 336 | "http://www.tvkaista.fi/netpvr/VLC?id=$ARGV[2]&format=$format", | 337 | "http://www.tvkaista.fi/netpvr/VLC?id=$ARGV[2]&format=$format", |
| 337 | '--load-cookies', '2/cookies.txt'; | 338 | '--load-cookies', '3/cookies.txt'; |
| 338 | | 339 | |
| 339 | open I, '<', $pagename or die "Can not open '$pagename': $!\n"; | 340 | open I, '<', $pagename or die "Can not open '$pagename': $!\n"; |
| 340 | my $url; | 341 | my $url; |
| 347 | die "No content found!\n"; | 348 | die "No content found!\n"; |
| 348 | } | 349 | } |
| 349 | | 350 | |
| 350 | my ($namepfx, $srtflen) = getsrt($ARGV[2], $ARGV[1]); | 351 | my ($namepfx, $srtflen) = getsrt($ARGV[3], $ARGV[1]); |
| 351 | chdir $recdir; | 352 | chdir $recdir; |
| 352 | | 353 | |
| 353 | my @list = ( $ARGV[1] ); | 354 | my @list = ( $ARGV[1] ); |
| 408 | # "list" (and "update" too) | 409 | # "list" (and "update" too) |
| 409 | select STDOUT; | 410 | select STDOUT; |
| 410 | | 411 | |
| 411 | my @prgfiles = <2/program_*[0-9]>; | 412 | my @prgfiles = <3/program_*[0-9]>; |
| 412 | unlink shift @prgfiles while defined $prgfiles[15]; | 413 | unlink shift @prgfiles while defined $prgfiles[15]; |
| 413 | foreach (@prgfiles) | 414 | foreach (@prgfiles) |
| 414 | { | 415 | { |
| tvkaista-0.964/tvkaista_gtkui.c | | tvkaista-0.971/tvkaista_gtkui.c |
| 26 | * Last modified: su 26. huhtikuuta 2009 18.39.07 too | 26 | * Last modified: su 26. huhtikuuta 2009 18.39.07 too |
| 27 | */ | 27 | */ |
| 28 | | 28 | |
| | 29 | /* thanks to gtk parasite (use internet search engine to find) |
| | 30 | * for figuring out some stuff. fetch, compile and then |
| | 31 | * execute 'GTK_MODULES=/path/to/gtpkarasite prog [args]' |
| | 32 | * |
| | 33 | * Example execution after gtkparasite build (without install): |
| | 34 | * GTK_MODULES=`pwd`/src/.libs/libgtkparasite.so tvkaista.sh gui |
| | 35 | */ |
| | 36 | |
| 29 | #define _GNU_SOURCE 1 // strcasestr() at least (in string.h). | 37 | #define _GNU_SOURCE 1 // strcasestr() at least (in string.h). |
| 30 | | 38 | |
| 31 | #include <gtk/gtk.h> | 39 | #include <gtk/gtk.h> |
| 95 | typedef struct | 103 | typedef struct |
| 96 | { | 104 | { |
| 97 | int id; | 105 | int id; |
| | 106 | int16_t channelindex; |
| 98 | int txtfileindex; | 107 | int16_t txtfileindex; |
| 99 | int txtoffset; | 108 | int txtoffset; |
| 100 | } PrgInfo; | 109 | } PrgInfo; |
| 101 | | 110 | |
| 103 | #define MAXSEARCHLEN 30 | 112 | #define MAXSEARCHLEN 30 |
| 104 | struct | 113 | struct |
| 105 | { | 114 | { |
| | 115 | int channelfilter; |
| | 116 | int16_t maxchannelindex; |
| 106 | bool8 dofilter; | 117 | bool8 dotextfiltering; |
| 107 | bool8 notidle; | 118 | bool8 notidle; |
| 108 | char * path; | 119 | char * path; |
| 109 | char compare[MAXSEARCHLEN + 2]; | 120 | char compare[MAXSEARCHLEN + 2]; |
| 155 | return popen(cmdline, "r"); | 166 | return popen(cmdline, "r"); |
| 156 | } | 167 | } |
| 157 | | 168 | |
| 158 | bool visible_rows(GtkTreeModel * model, GtkTreeIter * iter, gpointer data) | | |
| 159 | { | | |
| 160 | (void)data; | | |
| 161 | if (! G.dofilter) | | |
| 162 | return true; | | |
| 163 | | | |
| 164 | gchar * str; | | |
| 165 | gtk_tree_model_get (model, iter, 3, &str, -1); | | |
| 166 | if (!str) | | |
| 167 | return false; | | |
| 168 | gboolean visible = (strcasestr(str, G.compare) != null); | | |
| 169 | g_free(str); | | |
| 170 | return visible; | | |
| 171 | } | | |
| 172 | | | |
| 173 | enum | 169 | enum |
| 174 | { | 170 | { |
| 175 | COL_DATE = 0, | 171 | COL_DATE = 0, |
| 179 | COL_HIDDEN_INDEX, | 175 | COL_HIDDEN_INDEX, |
| 180 | NUM_COLS | 176 | NUM_COLS |
| 181 | }; | 177 | }; |
| | 178 | |
| | 179 | bool visible_rows(GtkTreeModel * model, GtkTreeIter * iter, gpointer data) |
| | 180 | { |
| | 181 | (void)data; |
| | 182 | |
| | 183 | if (G.channelfilter) { |
| | 184 | int indx; |
| | 185 | gtk_tree_model_get (model, iter, COL_HIDDEN_INDEX, &indx, -1); |
| | 186 | int i = indx / 1000, j = indx % 1000; |
| | 187 | PrgInfo * prginfo = &G.prgbuffers[i][j]; |
| | 188 | if (G.channelfilter != prginfo->channelindex) |
| | 189 | return false; |
| | 190 | } |
| | 191 | |
| | 192 | if (! G.dotextfiltering) |
| | 193 | return true; |
| | 194 | |
| | 195 | gchar * str; |
| | 196 | gtk_tree_model_get (model, iter, COL_PROGRAM, &str, -1); |
| | 197 | if (!str) |
| | 198 | return false; |
| | 199 | gboolean visible = (strcasestr(str, G.compare) != null); |
| | 200 | g_free(str); |
| | 201 | return visible; |
| | 202 | } |
| 182 | | 203 | |
| 183 | bool selected_row(GtkTreeSelection * selection, | 204 | bool selected_row(GtkTreeSelection * selection, |
| 184 | GtkTreeModel * model, GtkTreePath * path, | 205 | GtkTreeModel * model, GtkTreePath * path, |
| 311 | int offset = 0; | 332 | int offset = 0; |
| 312 | int indx = 0; | 333 | int indx = 0; |
| 313 | int prgdayindex = 0; | 334 | int prgdayindex = 0; |
| | 335 | int channelindex = 0; |
| 314 | char day[10]; | 336 | char day[10]; |
| 315 | char hourmin[8]; | 337 | char hourmin[8]; |
| 316 | char channel[16]; | 338 | char channel[16]; |
| 318 | | 340 | |
| 319 | while (!feof(fh)) | 341 | while (!feof(fh)) |
| 320 | { | 342 | { |
| 321 | char * ptrs[4]; | 343 | char * ptrs[5]; |
| 322 | char * p; | 344 | char * p; |
| 323 | if (fgets(line, sizeof line, fh) == null) | 345 | if (fgets(line, sizeof line, fh) == null) |
| 324 | die("fgets():"); | 346 | die("fgets():"); |
| 338 | prgdayindex, G.prgfile[prgdayindex], day)); | 360 | prgdayindex, G.prgfile[prgdayindex], day)); |
| 339 | continue; | 361 | continue; |
| 340 | case 'I': | 362 | case 'I': |
| 341 | splitstring(line + 2, ptrs, 4); | 363 | splitstring(line + 2, ptrs, 5); |
| 342 | id = atoi(ptrs[0]); | 364 | id = atoi(ptrs[0]); |
| 343 | xstrlcpy(hourmin, ptrs[1], sizeof hourmin); | 365 | xstrlcpy(hourmin, ptrs[1], sizeof hourmin); |
| | 366 | channelindex = atoi(ptrs[2]); |
| 344 | if (strcmp(ptrs[2], "Urheilukanava") == 0) | 367 | if (strcmp(ptrs[3], "Urheilukanava") == 0) |
| 345 | strcpy(channel, "Urheilukan."); | 368 | strcpy(channel, "Urheilukan."); |
| 346 | else | 369 | else |
| 347 | xstrlcpy(channel, ptrs[2], sizeof channel); | 370 | xstrlcpy(channel, ptrs[3], sizeof channel); |
| 348 | p = channel; while ((p = strchr(p, '_')) != null) *p = ' '; | 371 | p = channel; while ((p = strchr(p, '_')) != null) *p = ' '; |
| 349 | xstrlcpy(shortinfo, ptrs[3], sizeof shortinfo); | 372 | xstrlcpy(shortinfo, ptrs[4], sizeof shortinfo); |
| 350 | d0(("I | %d | %s | %s | %s\n", | 373 | d0(("I | %d | %s | %s | %s\n", |
| 351 | id, hourmin, channel, shortinfo)); | 374 | id, hourmin, channel, shortinfo)); |
| 352 | continue; | 375 | continue; |
| 376 | } | 399 | } |
| 377 | | 400 | |
| 378 | G.prgbuffers[i][j].id = id; | 401 | G.prgbuffers[i][j].id = id; |
| | 402 | G.prgbuffers[i][j].channelindex = channelindex; |
| 379 | G.prgbuffers[i][j].txtfileindex = prgdayindex; | 403 | G.prgbuffers[i][j].txtfileindex = prgdayindex; |
| 380 | G.prgbuffers[i][j].txtoffset = offset; | 404 | G.prgbuffers[i][j].txtoffset = offset; |
| | 405 | |
| | 406 | if (channelindex > G.maxchannelindex) |
| | 407 | G.maxchannelindex = channelindex; |
| 381 | | 408 | |
| 382 | /*fputs(line, stdout); */ | 409 | /*fputs(line, stdout); */ |
| 383 | gtk_list_store_append(liststore, &iter); | 410 | gtk_list_store_append(liststore, &iter); |
| 394 | return false; | 421 | return false; |
| 395 | } | 422 | } |
| 396 | | 423 | |
| | 424 | void day_clicked(int promille) |
| | 425 | { |
| | 426 | printf("day_clicked(%d) (no action, yet)\n", promille); |
| | 427 | } |
| | 428 | |
| | 429 | void time_clicked(int promille) |
| | 430 | { |
| | 431 | printf("time_clicked(%d) (no action, yet)\n", promille); |
| | 432 | } |
| | 433 | |
| | 434 | void channel_clicked(int promille) |
| | 435 | { |
| | 436 | printf("channel_clicked(%d)\n", promille); |
| | 437 | |
| | 438 | if (promille < 300) { |
| | 439 | if (G.channelfilter <= 1) |
| | 440 | G.channelfilter = G.maxchannelindex; |
| | 441 | else |
| | 442 | G.channelfilter--; |
| | 443 | } |
| | 444 | else if (promille > 600) { |
| | 445 | if (G.channelfilter == G.maxchannelindex) |
| | 446 | G.channelfilter = 1; |
| | 447 | else |
| | 448 | G.channelfilter++; |
| | 449 | } |
| | 450 | else |
| | 451 | G.channelfilter = 0; |
| | 452 | gtk_tree_model_filter_refilter(W.listfilter); |
| | 453 | G.notidle = false; |
| | 454 | } |
| | 455 | |
| | 456 | // ISO C forbids passing argument 4 of 'g_signal_connect_data' |
| | 457 | // between function pointer and 'void *' |
| | 458 | // therefore: |
| | 459 | // (every computer problem can be solved by another level of indirection) |
| | 460 | |
| | 461 | struct colhdr_cb { |
| | 462 | void (*func)(int); |
| | 463 | } colhdr_cbs[3] = { |
| | 464 | { day_clicked }, |
| | 465 | { time_clicked }, |
| | 466 | { channel_clicked } |
| | 467 | }; |
| | 468 | |
| | 469 | void colhdr_clicked(GtkTreeViewColumn * col, struct colhdr_cb * colhdr_cb) |
| | 470 | { |
| | 471 | int x, y, w; |
| | 472 | |
| | 473 | //gtk_tree_view_column_cell_get_size (col, null, &x, &y, &w, &h); |
| | 474 | w = gtk_tree_view_column_get_width(col); |
| | 475 | gtk_widget_get_pointer(col->button, &x, &y); |
| | 476 | |
| | 477 | // printf("pointer: x = %d, y = %d. width: %d, %d/1000\n",x,y,w,x*1000/w); |
| | 478 | |
| | 479 | colhdr_cb->func(x * 1000 / w); |
| | 480 | |
| | 481 | //printf("pointer: x = %d, y = %d\n", x, y); |
| | 482 | //printf("xxx: x = %d, y = %d, w = %d, h = %d\n", x,y,w,h); |
| | 483 | } |
| 397 | | 484 | |
| 398 | static GtkWidget * | 485 | static GtkWidget * |
| 399 | create_view_and_model (void) | 486 | create_view_and_model (void) |
| 406 | GtkTreeSelection * selection; | 493 | GtkTreeSelection * selection; |
| 407 | | 494 | |
| 408 | int i; | 495 | int i; |
| 409 | const char * colname[] = { "päivä", "kello", "kanava", "ohjelma" }; | 496 | const char * colname[] = { "<päivä>", "<klo>", "<kanava>", "ohjelma" }; |
| 410 | | 497 | |
| 411 | view = gtk_tree_view_new(); | 498 | view = gtk_tree_view_new(); |
| 412 | | 499 | |
| 421 | col = gtk_tree_view_column_new(); | 508 | col = gtk_tree_view_column_new(); |
| 422 | | 509 | |
| 423 | gtk_tree_view_column_set_title(col, colname[i]); | 510 | gtk_tree_view_column_set_title(col, colname[i]); |
| | 511 | if (i < 3) { |
| | 512 | gtk_tree_view_column_set_clickable(col, true); |
| | 513 | g_signal_connect(G_OBJECT(col), "clicked", |
| | 514 | G_CALLBACK(colhdr_clicked),(void*)&colhdr_cbs[i]); |
| | 515 | } |
| 424 | | 516 | |
| 425 | /* pack tree view column into tree view */ | 517 | /* pack tree view column into tree view */ |
| 426 | gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); | 518 | gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); |
| 677 | if (G.prgfd[i] >= 0) { close(G.prgfd[i]); G.prgfd[i] = -1; } | 769 | if (G.prgfd[i] >= 0) { close(G.prgfd[i]); G.prgfd[i] = -1; } |
| 678 | G.previndx = -1; | 770 | G.previndx = -1; |
| 679 | G.compare[0] = '\0'; | 771 | G.compare[0] = '\0'; |
| | 772 | G.channelfilter = 0; |
| | 773 | G.maxchannelindex = 0; |
| 680 | G.dofilter = false; // XXX see usage here and elsewhere | 774 | G.dotextfiltering = false; // XXX see usage here and elsewhere |
| 681 | } | 775 | } |
| 682 | | 776 | |
| 683 | bool reset_signal(void * inprogress_p) | 777 | bool reset_signal(void * inprogress_p) |
| 754 | //return false; | 848 | //return false; |
| 755 | if (strcmp(txt, G.compare) != 0) | 849 | if (strcmp(txt, G.compare) != 0) |
| 756 | strcpy(G.compare, txt); | 850 | strcpy(G.compare, txt); |
| 757 | G.dofilter = true; // XXX move elsewhere | 851 | G.dotextfiltering = true; // XXX move elsewhere |
| 758 | gtk_tree_model_filter_refilter(W.listfilter); | 852 | gtk_tree_model_filter_refilter(W.listfilter); |
| 759 | G.notidle = false; | 853 | G.notidle = false; |
| 760 | return false; | 854 | return false; |
| 807 | | 901 | |
| 808 | //g_signal_connect(e, "insert-at-cursor", entry_changed, null); | 902 | //g_signal_connect(e, "insert-at-cursor", entry_changed, null); |
| 809 | | 903 | |
| 810 | gtk_window_set_icon_from_file(W.w, "tvkaista.png", null); | 904 | gtk_window_set_icon_from_file(GTK_WINDOW(W.w), "tvkaista.png", null); |
| 811 | | 905 | |
| 812 | #if 0 | 906 | #if 0 |
| 813 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 907 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |