summaryrefslogtreecommitdiffstats
path: root/knewsticker/knt-0.1-0.2.pl
blob: 2ca9e30cade4cd7bc40006a3fd5c567fee21c5fa (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
#!/usr/bin/perl
# convert which file to which file?
# I did nto bother to build in any checks. so that file better exists and it is readable and the data will
# be written to a writeable directory. Since this is an old config file, it is safe to assume, that is the 
# case.

#$file = $ARGV[0];

# Take your hands off the rest unless you darn well knwo what you are doing
##################################################################################
##################################################################################

open(INFO, $file);  
 my ($section, %data);

#read in all the data, split it up into hashes. Thanks again to malte for much input
while (<>) {
	if (/\[(.*)\]/) {
		$sections{$section} = {%data} if $section;
		$section = $1;
		undef %data;
		next;
 	}
$data{$1} = $2 if /^([^=]*)=(.*)$/;
}

$sections{$section} = {%data} if $section;

# do the data writing magic
#first of all be check how many old news souerces we have

$sources = $sections{'General'}->{'News sources'}; 
#gather all news sources into a very pretty string before we write the global section
#also give some feedback to the user
for my $i (0..($sources-1)) { 
	$all .= "," .$sections{"News source #$i"}->{'Name'}; 
	$all =~s/^,//;
}

# write the main section
print "[KNewsTicker]\n";

while (($key,$dat) = each(%{$sections{'General'}})) {
	if ($key ne "News sources") { 
		if ($key eq "Interval") {
			$key="Update interval";
				}
		if ($key eq "Scroll most recent only") {
			$key="Scroll most recent headlines only";
				}
		print "$key=$dat\n";
		} else {
		print "News sources=".$all."\n";
		}	

}

# next merge the old scrolling section into the KNewticker Section
while (($key,$dat) = each(%{$sections{'Scrolling'}})) {
	 if ($key eq "Background") {
                $key="Background color";
		
                } 
	 if ($key eq "Foreground") {
                $key="Foreground color";
                }
	 if ($key eq "Highlighted") {
                $key="Highlighted color";
                }
	 if ($key eq "Underline highlighted") {
                $key="Underline highlighted headlines";
                }
	 if (($key eq "Direction") && ($dat eq "Left")) {
		$key ="Scrolling direction";
		$dat = "0";	

} 
if (($key eq "Direction") && ($dat ne "Left")) {

		$key ="Scrolling direction";

}
if ($key eq "Speed") {
	$key="Scrolling speed";
}



 print "$key=$dat\n"; 
} 

# next we write the news sources, making sure we have the correct headers
for my $i (0..($sources-1)) { 

print "\n[" .$sections{"News source #$i"}->{'Name'} ."]\n";
	while (($key,$dat) = each(%{$sections{"News source #$i"}})) {
	if ($key ne "Address") {
		print "$key=$dat\n";
		} else {
		print "Source file=".$dat."\n";
	}
	} 
}