1 #include <setup_timezone.h>
4 #include <lib/gui/slider.h>
5 #include <lib/gui/ebutton.h>
6 #include <lib/gui/elabel.h>
7 #include <lib/gui/combobox.h>
8 #include <lib/gui/echeckbox.h>
9 #include <lib/gui/enumber.h>
10 #include <lib/gui/eskin.h>
11 #include <lib/gui/actions.h>
12 #include <lib/system/econfig.h>
13 #include <enigma_main.h>
16 #define ZONEINFODIR DATADIR "/zoneinfo"
19 eZapTimeZoneSetup::eZapTimeZoneSetup(bool showHint
)
20 :eWindow(0), showHint(showHint
)
22 setText(_("Time Zone Setup"));
23 cmove(ePoint(110, 146));
24 cresize(eSize(530, 270));
26 int fd
=eSkin::getActive()->queryValue("fontsize", 20);
28 ltimeZone
=new eLabel(this);
29 ltimeZone
->move(ePoint(20, 20));
30 ltimeZone
->resize(eSize(220, fd
+4));
31 ltimeZone
->setText(_("Time Zone:"));
33 timeZone
=new eComboBox(this, 8, ltimeZone
);
34 timeZone
->move(ePoint(20, 60));
35 timeZone
->resize(eSize(clientrect
.width()-40, 35));
36 timeZone
->setHelpText(_("select your time zone (ok)"));
39 errLoadTimeZone
= loadTimeZones();
42 ok
->setText(_("save"));
43 ok
->setShortcut("green");
44 ok
->setShortcutPixmap("green");
45 ok
->move(ePoint(20, clientrect
.height()-100));
46 ok
->resize(eSize(220, 40));
47 ok
->setHelpText(_("save changes and return"));
49 CONNECT(ok
->selected
, eZapTimeZoneSetup::okPressed
);
51 statusbar
=new eStatusBar(this);
52 statusbar
->move( ePoint(0, clientrect
.height()-50 ) );
53 statusbar
->resize( eSize( clientrect
.width(), 50) );
54 statusbar
->loadDeco();
65 bool operator()(eListBoxEntryText
&e
)
67 delete (eString
*)(e
.getKey());
72 eZapTimeZoneSetup::~eZapTimeZoneSetup()
74 timeZone
->forEachEntry(delString());
77 void eZapTimeZoneSetup::okPressed()
81 // save current selected time zone
82 if ( eConfig::getInstance()->setKey("/elitedvb/timezone", ((eString
*) timeZone
->getCurrent()->getKey())->c_str()))
84 eConfig::getInstance()->delKey("/elitedvb/timezone");
85 eDebug("Write timezone with error %i", eConfig::getInstance()->setKey("/elitedvb/timezone", ((eString
*) timeZone
->getCurrent()->getKey())->c_str()));
87 eConfig::getInstance()->flush();
91 eMessageBox
msg(_("You have to restart enigma to apply the new Timezone\nRestart now?"), _("Timezone changed"), eMessageBox::btYes
|eMessageBox::btNo
|eMessageBox::iconQuestion
, eMessageBox::btYes
);
93 if ( msg
.exec() == eMessageBox::btYes
)
103 void eZapTimeZoneSetup::setTimeZone()
105 char *ctimeZone
=cmdTimeZones();
108 "cp " ZONEINFODIR
"/%s /var/etc/localtime",
109 ctimeZone
).c_str() ) >> 8)
110 eDebug("couldn't set timezone");
114 int eZapTimeZoneSetup::loadTimeZones()
116 XMLTreeParser
parser("ISO-8859-1");
118 const char *filename
="/etc/timezone.xml";
120 FILE *in
=fopen(filename
, "rt");
123 eWarning("unable to open %s", filename
);
129 unsigned int len
=fread(buf
, 1, sizeof(buf
), in
);
130 done
=len
<sizeof(buf
);
131 if (!parser
.Parse(buf
, len
, done
))
133 eDebug("parse error: %s at line %d",
134 parser
.ErrorString(parser
.GetErrorCode()),
135 parser
.GetCurrentLineNumber());
142 XMLTreeNode
*root
=parser
.RootNode();
147 if ( eConfig::getInstance()->getKey("/elitedvb/timezone", ctimeZone
) )
150 eListBoxEntryText
*cur
=0;
151 for (XMLTreeNode
*node
= root
->GetChild(); node
; node
= node
->GetNext())
152 if (!strcmp(node
->GetType(), "zone"))
154 const char *name
=node
->GetAttributeValue("name");
157 eFatal("error in a file timezone.xml, no name timezone");
160 eListBoxEntryText
*tz
=new eListBoxEntryText( *timeZone
, name
, (void*) new eString(name
) );
161 if ( ctimeZone
&& !strcmp(ctimeZone
, name
) )
166 eFatal("error in a file timezone.xml, unknown timezone");
168 if ( timeZone
->setCurrent(cur
) == eComboBox::E_INVALID_ENTRY
)
169 timeZone
->setCurrent(27); // GMT+1
176 char *eZapTimeZoneSetup::cmdTimeZones()
178 XMLTreeParser
parser("ISO-8859-1");
180 const char *filename
="/etc/timezone.xml";
182 FILE *in
=fopen(filename
, "rt");
185 eWarning("unable to open %s", filename
);
191 unsigned int len
=fread(buf
, 1, sizeof(buf
), in
);
192 done
=len
<sizeof(buf
);
193 if (!parser
.Parse(buf
, len
, done
))
195 eDebug("parse error: %s at line %d",
196 parser
.ErrorString(parser
.GetErrorCode()),
197 parser
.GetCurrentLineNumber());
204 XMLTreeNode
*root
=parser
.RootNode();
209 if ( eConfig::getInstance()->getKey("/elitedvb/timezone", ctimeZone
) )
212 for (XMLTreeNode
*node
= root
->GetChild(); node
; node
= node
->GetNext())
213 if (!strcmp(node
->GetType(), "zone"))
215 const char *name
=node
->GetAttributeValue("name"),
216 *zone
=node
->GetAttributeValue("zone");
217 // *dst=node->GetAttributeValue("dst");
220 eFatal("error in a file timezone.xml, no name timezone");
224 if ( ctimeZone
&& !strcmp(ctimeZone
, name
) )
231 eFatal("error in file timezone.xml, unknown timezone");