Ticket #6290: 00-mythtv-setup.patch
File 00-mythtv-setup.patch, 16.8 KB (added by , 15 years ago) |
---|
-
mythtv/programs/mythtv-setup/mythtv-setup.pro
23 23 } 24 24 25 25 # Input 26 HEADERS += backendsettings.h checksetup.h exitprompt.h importicons.h26 HEADERS += backendsettings.h checksetup.h importicons.h setupdialog.h 27 27 HEADERS += channeleditor.h 28 SOURCES += backendsettings.cpp checksetup.cpp exitprompt.cpp main.cpp28 SOURCES += backendsettings.cpp checksetup.cpp setupdialog.cpp main.cpp 29 29 SOURCES += importicons.cpp channeleditor.cpp 30 30 31 31 macx { -
mythtv/programs/mythtv-setup/exitprompt.cpp
1 #include <QApplication>2 3 // MythTV stuff4 #include "exitcodes.h"5 #include "mythcontext.h"6 #include "mythcontext.h"7 #include "mythdialogbox.h"8 #include "mythmainwindow.h"9 #include "mythscreenstack.h"10 #include "remoteutil.h"11 12 #include "checksetup.h"13 #include "exitprompt.h"14 15 struct ExitPrompterPrivate16 {17 ExitPrompterPrivate()18 {19 stk = GetMythMainWindow()->GetStack("popup stack");20 }21 22 MythScreenStack *stk;23 };24 25 ExitPrompter::ExitPrompter()26 {27 m_d = new ExitPrompterPrivate;28 }29 30 ExitPrompter::~ExitPrompter()31 {32 delete m_d;33 }34 35 void ExitPrompter::masterPromptExit()36 {37 if (gContext->IsMasterHost())38 {39 QString prompt = tr("If this is the master backend server,"40 " please run 'mythfilldatabase' to populate"41 " the database with channel information.");42 43 MythDialogBox *dia = new MythDialogBox(prompt, m_d->stk, "fill prompt");44 if (!dia->Create())45 {46 VERBOSE(VB_IMPORTANT, "Can't create fill DB prompt?");47 delete dia;48 quit();49 }50 dia->AddButton(tr("OK"), SLOT(quit()));51 52 // This is a hack so that the button clicks target the correct slot:53 dia->SetReturnEvent(this, QString());54 55 m_d->stk->AddScreen(dia);56 }57 else58 quit();59 }60 61 void ExitPrompter::handleExit()62 {63 QStringList problems;64 65 // Look for common problems66 if (CheckSetup(problems))67 {68 problems.push_back(QString());69 if (problems.size() > 1)70 problems.push_back(tr("Do you want to fix these problems?"));71 else72 problems.push_back(tr("Do you want to fix this problem?"));73 74 MythDialogBox *dia = new MythDialogBox(problems.join("\n"),75 m_d->stk, "exit prompt");76 if (!dia->Create())77 {78 VERBOSE(VB_IMPORTANT, "Can't create Exit Prompt dialog?");79 delete dia;80 quit();81 }82 dia->AddButton(tr("Yes please"));83 dia->AddButton(tr("No, I know what I am doing"),84 SLOT(masterPromptExit()));85 86 // This is a hack so that the button clicks target the correct slot:87 dia->SetReturnEvent(this, QString());88 89 m_d->stk->AddScreen(dia);90 }91 else92 masterPromptExit();93 }94 95 void ExitPrompter::quit()96 {97 if (gContext->BackendIsRunning())98 RemoteSendMessage("CLEAR_SETTINGS_CACHE");99 100 qApp->exit(GENERIC_EXIT_OK);101 } -
mythtv/programs/mythtv-setup/exitprompt.h
1 #include <QObject>2 3 #define NO_EXIT 04 #define QUIT 15 #define HALT 26 #define REBOOT 37 8 class ExitPrompter : public QObject9 {10 Q_OBJECT11 12 public:13 ExitPrompter();14 ~ExitPrompter();15 16 public slots:17 void masterPromptExit();18 void handleExit();19 void quit();20 21 private:22 ExitPrompter(const ExitPrompter &);23 24 private:25 struct ExitPrompterPrivate *m_d;26 }; -
mythtv/programs/mythtv-setup/setupdialog.cpp
1 // ANSI C 2 #include <cstdlib> 3 4 // POSIX 5 #include <unistd.h> 6 7 // qt 8 #include <QApplication> 9 #include <QKeyEvent> 10 #include <QLabel> 11 #include <QEvent> 12 13 // myth 14 #include "libmythtv/videosource.h" 15 #include "libmythui/mythprogressdialog.h" 16 #include "channeleditor.h" 17 #include "compat.h" 18 #include "exitcodes.h" 19 #include "lcddevice.h" 20 #include "mythcontext.h" 21 #include "mythdbcon.h" 22 #include "mythdirs.h" 23 #include "myththemedmenu.h" 24 #include "mythuihelper.h" 25 #include "programinfo.h" 26 #include "remoteutil.h" 27 #include "storagegroup.h" 28 #include "tv.h" 29 #include "uitypes.h" 30 31 #include "backendsettings.h" 32 #include "setupdialog.h" 33 #include "checksetup.h" 34 35 void SetupMenuCallback ( void* data, QString& selection ) 36 { 37 (void)data; 38 39 QString sel = selection.toLower(); 40 41 if ( sel == "general" ) 42 { 43 BackendSettings be; 44 be.exec(); 45 } 46 else if ( sel == "capture cards" ) 47 { 48 CaptureCardEditor cce; 49 cce.exec(); 50 } 51 else if ( sel == "video sources" ) 52 { 53 VideoSourceEditor vse; 54 vse.exec(); 55 } 56 else if ( sel == "card inputs" ) 57 { 58 CardInputEditor cie; 59 cie.exec(); 60 } 61 else if ( sel == "channel editor" ) 62 { 63 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); 64 65 ChannelEditor *chanedit = new ChannelEditor(mainStack); 66 67 if (chanedit->Create()) 68 mainStack->AddScreen(chanedit); 69 else 70 delete chanedit; 71 } 72 else if ( sel == "storage groups" ) 73 { 74 StorageGroupListEditor sge; 75 sge.exec(); 76 } 77 } 78 79 80 SetupDialog::SetupDialog(MythScreenStack *parent, const char *name) 81 :MythScreenType(parent, name) 82 { 83 gContext->addListener(this); 84 85 m_menuPopup = NULL; 86 m_restartBackend = false; 87 m_haveProblems = false; 88 m_terminate = false; 89 } 90 91 void SetupDialog::Start(void) 92 { 93 // Offer to stop the backend if sensible 94 if (gContext->BackendIsRunning() && gContext->IsMasterHost()) 95 { 96 ShowBackendMenu(); 97 } 98 else 99 { 100 ShowSetupMenu(); 101 } 102 103 } 104 105 void SetupDialog::ShowSetupMenu(void) 106 { 107 QString theme = gContext->GetSetting("Theme", "blue"); 108 109 MythMainWindow *win = GetMythMainWindow(); 110 111 MythThemedMenu* menu = new MythThemedMenu(GetMythUI()->FindThemeDir(theme), 112 "setup.xml", win->GetMainStack(), 113 "mainmenu", false); 114 115 menu->setCallback(SetupMenuCallback, gContext); 116 menu->setKillable(); 117 118 if ( menu->foundTheme() ) 119 { 120 win->GetMainStack()->AddScreen(menu); 121 } 122 else 123 { 124 VERBOSE(VB_IMPORTANT, QString("Couldn't find theme '%1'").arg(theme)); 125 } 126 } 127 128 129 void SetupDialog::CloseDialog() 130 { 131 // If the backend was stopped restart it here 132 if (m_restartBackend) 133 { 134 QString commandString = gContext->GetSetting("BackendStartCommand"); 135 if (!commandString.isEmpty()) 136 { 137 VERBOSE(VB_IMPORTANT, "backendrestart"+commandString); 138 myth_system(commandString); 139 } 140 } 141 else 142 { 143 // No need to run this if the backend has just restarted 144 if (gContext->BackendIsRunning()) 145 { 146 RemoteSendMessage("CLEAR_SETTINGS_CACHE"); 147 } 148 } 149 150 m_terminate = true; 151 qApp->exit(GENERIC_EXIT_OK); 152 } 153 154 void SetupDialog::StopBackend() 155 { 156 VERBOSE(VB_IMPORTANT, "Trying to stop backend"); 157 158 QString commandString = gContext->GetSetting("BackendStopCommand"); 159 if (!commandString.isEmpty()) 160 { 161 myth_system(commandString); 162 } 163 m_restartBackend = true; 164 165 //todo check mythbackend was stopped 166 ShowSetupMenu(); 167 } 168 169 void SetupDialog::ContinueWithBackendRunning() 170 { 171 VERBOSE(VB_IMPORTANT, "Continuing with backend running"); 172 ShowSetupMenu(); 173 } 174 175 176 SetupDialog::~SetupDialog() 177 { 178 gContext->removeListener(this); 179 } 180 181 void SetupDialog::ShowBackendMenu(void) 182 { 183 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 184 185 bool backendIsRecording = false; 186 // Get recording status 187 if (!gContext->IsConnectedToMaster()) 188 { 189 gContext->ConnectToMasterServer(false); 190 backendIsRecording = RemoteGetRecordingStatus(NULL, false); 191 } 192 193 QString warning = tr("WARNING: The backend is currently running.")+"\n\n"+ 194 tr("Changing existing card inputs, deleting anything, " 195 "or scanning for channels may not work.")+"\n\n"; 196 if (backendIsRecording) 197 { 198 warning += tr("Recording Status: RECORDING.")+"\n"+ 199 tr("If you stop the backend now these recordings will be stopped!"); 200 } 201 else 202 { 203 warning += tr("Recording Status: None."); 204 } 205 206 m_menuPopup = new MythDialogBox(warning, popupStack, "actionmenu"); 207 208 if (m_menuPopup->Create()) 209 popupStack->AddScreen(m_menuPopup); 210 211 m_menuPopup->SetReturnEvent(this, "action"); 212 213 QString commandString = gContext->GetSetting("BackendStopCommand"); 214 if (!commandString.isEmpty()) 215 { 216 // Only show option to stop backend if command is defined. 217 m_menuPopup->AddButton(tr("Stop Backend and Continue"), SLOT(StopBackend())); 218 } 219 m_menuPopup->AddButton(tr("Continue"), SLOT(ContinueWithBackendRunning())); 220 m_menuPopup->AddButton(tr("Exit"), SLOT(CloseDialog())); 221 } 222 223 224 void SetupDialog::ShowExitMenu(void) 225 { 226 // Look for common problems 227 QStringList problems; 228 229 if (CheckSetup(problems)) 230 { 231 problems.push_back(QString()); 232 if (problems.size() > 1) 233 { 234 problems.push_back(tr("Do you want to fix these problems?")); 235 } 236 else 237 { 238 problems.push_back(tr("Do you want to fix this problem?")); 239 } 240 241 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 242 243 m_menuPopup = new MythDialogBox(problems.join("\n"), popupStack, "actionmenu"); 244 245 if (m_menuPopup->Create()) 246 { 247 popupStack->AddScreen(m_menuPopup); 248 249 m_menuPopup->SetReturnEvent(this, "action"); 250 251 m_menuPopup->AddButton(tr("Yes (Return to Setup Menu)"), SLOT(ContinueWithBackendRunning())); 252 m_menuPopup->AddButton(tr("No (Exit)"), SLOT(ShowMFDExitMenu())); 253 } 254 else 255 { 256 VERBOSE(VB_IMPORTANT, "Can't create Exit Prompt dialog?"); 257 delete m_menuPopup; 258 ShowMFDExitMenu(); 259 } 260 261 } 262 else 263 { 264 ShowMFDExitMenu(); 265 } 266 267 } 268 269 void SetupDialog::ShowMFDExitMenu(void) 270 { 271 if (gContext->IsMasterHost()) 272 { 273 QString prompt = tr("If this is the master backend server," 274 " please run 'mythfilldatabase' to populate" 275 " the database with channel information."); 276 277 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 278 279 MythDialogBox *dia = new MythDialogBox(prompt, popupStack, "fill prompt"); 280 if (!dia->Create()) 281 { 282 VERBOSE(VB_IMPORTANT, "Can't create fill DB prompt?"); 283 delete dia; 284 } 285 dia->AddButton(tr("OK")); 286 } 287 CloseDialog(); 288 } 289 290 bool SetupDialog::Terminate(void) 291 { 292 return m_terminate; 293 } -
mythtv/programs/mythtv-setup/main.cpp
13 13 #include "mythversion.h" 14 14 #include "langsettings.h" 15 15 #include "exitcodes.h" 16 #include "exitprompt.h"17 16 #include "storagegroup.h" 18 #include "myththemedmenu.h"19 17 #include "myththemebase.h" 20 18 #include "mythuihelper.h" 21 19 #include "mythdirs.h" 22 20 23 21 #include "libmythtv/dbcheck.h" 24 #include "libmythtv/videosource.h" 25 #include "channeleditor.h" 26 #include "libmythtv/remoteutil.h" 27 #include "backendsettings.h" 28 #include "checksetup.h" 22 #include "setupdialog.h" 29 23 30 24 using namespace std; 31 25 32 ExitPrompter *exitPrompt = NULL;33 34 void SetupMenuCallback(void* data, QString& selection)35 {36 (void)data;37 38 QString sel = selection.toLower();39 40 if (sel == "general")41 {42 BackendSettings be;43 be.exec();44 }45 else if (sel == "capture cards")46 {47 CaptureCardEditor cce;48 cce.exec();49 }50 else if (sel == "video sources")51 {52 VideoSourceEditor vse;53 vse.exec();54 }55 else if (sel == "card inputs")56 {57 CardInputEditor cie;58 cie.exec();59 }60 else if (sel == "channel editor")61 {62 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();63 64 ChannelEditor *chanedit = new ChannelEditor(mainStack);65 66 if (chanedit->Create())67 mainStack->AddScreen(chanedit);68 else69 delete chanedit;70 }71 else if (sel == "storage groups")72 {73 StorageGroupListEditor sge;74 sge.exec();75 }76 else if (sel == "exiting_app")77 {78 if (!exitPrompt)79 exitPrompt = new ExitPrompter();80 exitPrompt->handleExit();81 }82 else83 VERBOSE(VB_IMPORTANT, "Unknown menu action: " + selection);84 }85 86 void SetupMenu(MythMainWindow *win)87 {88 QString theme = gContext->GetSetting("Theme", "blue");89 90 MythThemedMenu* menu = new MythThemedMenu(GetMythUI()->FindThemeDir(theme),91 "setup.xml", win->GetMainStack(),92 "mainmenu", false);93 94 menu->setCallback(SetupMenuCallback, gContext);95 96 if (menu->foundTheme())97 {98 win->GetMainStack()->AddScreen(menu);99 qApp->exec();100 }101 else102 {103 VERBOSE(VB_IMPORTANT, QString("Couldn't find theme '%1'").arg(theme));104 }105 }106 107 26 int main(int argc, char *argv[]) 108 27 { 109 28 QString geometry = QString::null; … … 320 239 return GENERIC_EXIT_DB_OUTOFDATE; 321 240 } 322 241 323 QString warn =324 QObject::tr("WARNING") + ": " +325 QObject::tr("MythTV has detected that the backend is running.")+"\n\n"+326 QObject::tr("Changing existing card inputs, deleting anything, "327 "or scanning for channels may not work.");328 329 bool backendIsRunning = gContext->BackendIsRunning();330 331 if (backendIsRunning)332 {333 DialogCode val = MythPopupBox::Show2ButtonPopup(334 mainWindow, QObject::tr("WARNING"), warn,335 QObject::tr("Continue"),336 QObject::tr("Exit"), kDialogCodeButton0);337 338 if (kDialogCodeButton1 == val)339 {340 return GENERIC_EXIT_OK;341 }342 }343 344 242 REG_KEY("qt", "DELETE", "Delete", "D"); 345 243 REG_KEY("qt", "EDIT", "Edit", "E"); 346 244 245 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); 246 247 SetupDialog *setup = new SetupDialog(mainStack, "mythtv-setup"); 248 249 setup->Start(); 250 251 do 347 252 { 348 // Let the user select buttons, type values, scan for channels, etc. 349 SetupMenu(mainWindow); 350 } 351 // Main menu callback to ExitPrompter does CheckSetup(), cleanup and exit. 253 qApp->exec(); 254 setup->ShowExitMenu(); 255 } while (!setup->Terminate()); 256 257 return GENERIC_EXIT_OK; 258 352 259 } 353 260 354 261 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
mythtv/programs/mythtv-setup/setupdialog.h
1 #ifndef SETUPDIALOG_H_ 2 #define SETUPDIALOG_H_ 3 4 // qt 5 6 // myth 7 #include "mythscreentype.h" 8 #include "mythdialogbox.h" 9 10 class SetupDialog : public MythScreenType 11 { 12 13 Q_OBJECT 14 15 public: 16 17 SetupDialog(MythScreenStack *parent, const char *name); 18 ~SetupDialog(); 19 20 void Start(void); 21 void ShowExitMenu(void); 22 void ShowMFDExitMenu(void); 23 bool Terminate(void); 24 25 protected slots: 26 void CloseDialog(void); 27 void StopBackend(void); 28 void ContinueWithBackendRunning(void); 29 30 private: 31 32 MythDialogBox *m_menuPopup; 33 bool m_restartBackend; // true if the backend should be restarted on exit 34 bool m_haveProblems; // true if problems were encountered in checksetup 35 bool m_terminate; // true if mythtv-setup has finished and should terminate 36 37 void ShowSetupMenu(void); 38 void ShowBackendMenu(void); 39 40 41 42 }; 43 44 #endif