Skip to content

Commit

Permalink
Mythwelcome update from bullestock. Closes #4385.
Browse files Browse the repository at this point in the history
1) The date format was hardcoded - You can now specify the date format to 
   use on MythWelcome's settings page.
2) Two instances of the string "to" were not marked for translation.
3) Misplaced parenthesis in the 'upcoming recording' status area.
4) You can now use -l to specify a log file, in the same manner as for
   mythfrontend.

git-svn-id: http://svn.mythtv.org/svn/trunk@15261 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
Paul Harrison committed Dec 30, 2007
1 parent 2537bce commit 0212743
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
80 changes: 79 additions & 1 deletion mythtv/programs/mythwelcome/main.cpp
@@ -1,5 +1,9 @@
#include <qapplication.h>
#include <cstdlib>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "libmyth/mythcontext.h"
#include "libmyth/settings.h"
Expand All @@ -12,6 +16,13 @@
#include "welcomedialog.h"
#include "welcomesettings.h"


QString logfile = "";

static bool log_rotate(bool report_error);
static void log_rotate_handler(int);


void initKeys(void)
{
REG_KEY("Welcome", "STARTXTERM", "Open an Xterm window", "F12");
Expand Down Expand Up @@ -67,16 +78,47 @@ int main(int argc, char **argv)
{
bShowSettings = true;
}
else if (!strcmp(a.argv()[argpos], "-l") ||
!strcmp(a.argv()[argpos], "--logfile"))
{
if (a.argc()-1 > argpos)
{
logfile = a.argv()[argpos+1];
if (logfile.startsWith("-"))
{
cerr << "Invalid or missing argument to -l/--logfile option\n";
return FRONTEND_EXIT_INVALID_CMDLINE;
}
else
{
++argpos;
}
}
else
{
cerr << "Missing argument to -l/--logfile option\n";
return FRONTEND_EXIT_INVALID_CMDLINE;
}
}
else
{
cerr << "Invalid argument: " << a.argv()[argpos] << endl <<
"Valid options are: " << endl <<
"-v or --verbose debug-level Use '-v help' for level info" << endl <<
"-s or --setup Run setup for the mythshutdown program" << endl;
"-s or --setup Run setup for the mythshutdown program" << endl <<
"-l or --logfile filename Writes STDERR and STDOUT messages to filename" << endl;
return FRONTEND_EXIT_INVALID_CMDLINE;
}
}

if (logfile != "")
{
if (!log_rotate(true))
cerr << "cannot open logfile; using stdout/stderr" << endl;
else
signal(SIGHUP, &log_rotate_handler);
}

LanguageSettings::load("mythfrontend");

gContext->LoadQtConfig();
Expand Down Expand Up @@ -105,3 +147,39 @@ int main(int argc, char **argv)

return 0;
}


static bool log_rotate(bool report_error)
{
int new_logfd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0664);

if (new_logfd < 0)
{
/* If we can't open the new logfile, send data to /dev/null */
if (report_error)
{
cerr << "cannot open logfile " << logfile << endl;
return false;
}

new_logfd = open("/dev/null", O_WRONLY);

if (new_logfd < 0)
{
/* There's not much we can do, so punt. */
return false;
}
}

while (dup2(new_logfd, 1) < 0 && errno == EINTR);
while (dup2(new_logfd, 2) < 0 && errno == EINTR);
while (close(new_logfd) < 0 && errno == EINTR);

return true;
}


static void log_rotate_handler(int)
{
log_rotate(false);
}
14 changes: 9 additions & 5 deletions mythtv/programs/mythwelcome/welcomedialog.cpp
Expand Up @@ -45,6 +45,8 @@ WelcomeDialog::WelcomeDialog(MythMainWindow *parent,
gContext->GetNumSetting("idleWaitForRecordingTime", 15);

m_timeFormat = gContext->GetSetting("TimeFormat", "h:mm AP");
m_dateFormat = gContext->GetSetting("MythWelcomeDateFormat", "dddd\\ndd MMM yyyy");
m_dateFormat.replace("\\n", "\n");

// if idleTimeoutSecs is 0, the user disabled the auto-shutdown feature
m_bWillShutdown = (gContext->GetNumSetting("idleTimeoutSecs", 0) != 0);
Expand Down Expand Up @@ -221,6 +223,9 @@ void WelcomeDialog::keyPressEvent(QKeyEvent *e)
RemoteSendMessage("CLEAR_SETTINGS_CACHE");
updateStatus();
updateScreen();

m_dateFormat = gContext->GetSetting("MythWelcomeDateFormat", "dddd\\ndd MMM yyyy");
m_dateFormat.replace("\\n", "\n");
}
}
else if (action == "SHOWSETTINGS")
Expand Down Expand Up @@ -333,7 +338,7 @@ void WelcomeDialog::updateTime(void)
if (s != m_time_text->GetText())
m_time_text->SetText(s);

s = QDateTime::currentDateTime().toString("dddd\ndd MMM yyyy");
s = QDateTime::currentDateTime().toString(m_dateFormat);

if (s != m_date_text->GetText())
m_date_text->SetText(s);
Expand Down Expand Up @@ -374,7 +379,7 @@ void WelcomeDialog::updateScreen(void)
if (tuner->program.subtitle != "")
status += "\n(" + tuner->program.subtitle + ")";
status += "\n" + tuner->program.startTime.toString("hh:mm") +
" to " + tuner->program.endTime.toString("hh:mm");
" " + tr("to") + " " + tuner->program.endTime.toString("hh:mm");
}
else
status = QString(tr("Tuner %1 is not recording")).arg(tuner->id);
Expand Down Expand Up @@ -404,9 +409,8 @@ void WelcomeDialog::updateScreen(void)
if (prog->subtitle != "")
status += "\n(" + prog->subtitle + ")";

status += "\n" + prog->startTime.
toString("ddd dd MMM yyyy (hh:mm") + " to " +
prog->endTime.toString("hh:mm)");
status += "\n" + prog->startTime.toString(m_dateFormat + " (" + m_timeFormat) +
" " + tr("to") + " " + prog->endTime.toString("hh:mm)");

if (m_screenScheduledNo < m_scheduledList.count() - 1)
m_screenScheduledNo++;
Expand Down
1 change: 1 addition & 0 deletions mythtv/programs/mythwelcome/welcomedialog.h
Expand Up @@ -70,6 +70,7 @@ class WelcomeDialog : public MythThemedDialog

QString m_installDir;
QString m_timeFormat;
QString m_dateFormat;
bool m_isRecording;
bool m_hasConflicts;
bool m_bWillShutdown;
Expand Down
13 changes: 13 additions & 0 deletions mythtv/programs/mythwelcome/welcomesettings.cpp
Expand Up @@ -74,6 +74,17 @@ static HostCheckBox *ShutdownWithBE()
return gc;
};

static HostLineEdit *MythWelcomeDateFormat()
{
HostLineEdit *gc = new HostLineEdit("MythWelcomeDateFormat");
gc->setLabel(QObject::tr("Date Format"));
gc->setValue("dddd\ndd MMM yyyy");
gc->setHelpText(QObject::tr("This is the format to use to display the date. "
"See http://doc.trolltech.com/3.3/qdate.html#toString "
"for a list of valid format specifiers."));
return gc;
};

MythWelcomeSettings::MythWelcomeSettings()
{
HorizontalConfigurationGroup* hcg1 =
Expand Down Expand Up @@ -103,6 +114,8 @@ MythWelcomeSettings::MythWelcomeSettings()
vcg->addChild(ShutdownWithBE());
}

vcg->addChild(MythWelcomeDateFormat());

addChild(vcg);
}

Expand Down

0 comments on commit 0212743

Please sign in to comment.