summaryrefslogtreecommitdiffstats
path: root/abs/core/mythinstall/MythVantage-app/mythbeselect/main.cpp
blob: 7c5f9f22f332db1b02270089cfa700e310f32db4 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <qapplication.h>
#include <cstdlib>
//#include "libmyth/mythdialogs.h"
#include "libmyth/mythcontext.h"
#include "libmyth/settings.h"
#include "libmyth/langsettings.h"
#include "libmyth/mythdbcon.h"
#include <libmyth/exitcodes.h>
#include "libmythtv/tv.h"

#include "mythdialogbox.h"

#include <iostream>
#include <fstream>
#include <stdio.h>

#include "libmyth/dialogbox.h"
#include <qlist.h>
#include <qvaluevector.h>
#include "installdialog.h"
void initKeys(void)
{
    REG_KEY("Welcome", "STARTXTERM", "Open an Xterm window", "F12");
    REG_KEY("Welcome", "SHOWSETTINGS", "Show Mythshutdown settings", "F11");
}

int main(int argc, char **argv)
{
    QString becommand;
    QApplication a(argc, argv);
    bool bShow=false;
    gContext = NULL;
    gContext = new MythContext(MYTH_BINARY_VERSION);
    if (!gContext->Init())
    {
        VERBOSE(VB_IMPORTANT, "mythwelcome: Could not initialize myth context. "
                        "Exiting.");
        return FRONTEND_EXIT_NO_MYTHCONTEXT;
    }

    if (!MSqlQuery::testDBConnection())
    {
        VERBOSE(VB_IMPORTANT, "mythwelcome: Could not open the database. "
                        "Exiting.");
        return -1;
    }

    if ( a.argc() == 1 )
                {
                 VERBOSE(VB_IMPORTANT, "Not enough argurments");
                 exit(1);
                }
    // Check command line arguments
    for (int argpos = 1; argpos < a.argc(); ++argpos)
    {
             //    ++argpos;

	if (!strcmp(a.argv()[argpos],"-restart"))
        {
                 becommand="restart";
        }
         else if (!strcmp(a.argv()[argpos],"-start"))
        {
            becommand="start";
        }
        else if (!strcmp(a.argv()[argpos],"-stop"))
        {
            becommand="stop";
        }
      else if (!strcmp(a.argv()[argpos],"-forceshow"))
        {
             bShow=true;
        }
          else
        {
            cerr << "Invalid argument: " << a.argv()[argpos] << endl <<
                    "Valid options are: " << endl <<
                    "-restart " << endl <<
                    "-start " << endl <<
                    "-stop  " << endl <<
                    "-forceshow" << endl;

            return FRONTEND_EXIT_INVALID_CMDLINE;
        }


    }

    gContext->LoadQtConfig();



  QStringList msg;
  QString tempip;
  QString justifyip;
  QString temphname;
  QString justifyname;
  QString tempbetype;
  QString justifybetype;

  int listmaxpos = 0 ;
  typedef QValueVector<QString> BEvector;
  BEvector BElist (20);

   if (!MSqlQuery::testDBConnection())
    {
        VERBOSE(VB_IMPORTANT, "mythwelcome: Could not open the database. "
                        "Exiting.");
    }

  //select the master backend
           MSqlQuery query(MSqlQuery::InitCon());
            query.prepare( "SELECT DISTINCT  data,hostname from settings where value='MasterServerIP';");
            if (query.exec() && query.isActive() && query.size() > 0)
            {
                while (query.next())
                {

                    tempip = query.value(0).toString();
                    justifyip=tempip.rightJustify(15,' ',false);
                    temphname = query.value(1).toString();
                    justifyname= temphname.rightJustify( 20, ' ',false );

                    if ( temphname == "" )
                            tempbetype="MBE: ";
                            else
                            tempbetype="SBE: ";

                            tempbetype.append(justifyname);
                            tempbetype.append("  ");
                            tempbetype.append(justifyip);

                            justifybetype= tempbetype.leftJustify(50,' ' ,true);
                            BElist[listmaxpos] = tempbetype;
                            msg << (justifybetype);
                            listmaxpos++;
                }
             }


             //slave backends
            query.prepare( "SELECT DISTINCT  data,hostname from settings where value='BackendServerIP'  and  not data=:ip  ;");
               query.bindValue( ":ip", tempip );
            if (query.exec() && query.isActive() && query.size() > 0)
            {
                while (query.next())
                {

                    tempip = query.value(0).toString();
                    justifyip=tempip.rightJustify(15,' ',false);
                    temphname = query.value(1).toString();
                    justifyname= temphname.rightJustify( 20, ' ',false );

                    if ( temphname == "" )
                            tempbetype="MBE: ";
                            else
                            tempbetype="SBE: ";

                            tempbetype.append(justifyname);
                            tempbetype.append("  ");
                            tempbetype.append(justifyip);

                            justifybetype= tempbetype.leftJustify(50,' ' ,true);
                            BElist[listmaxpos] = tempbetype;
                            msg << (justifybetype);
                            listmaxpos++;
                }
             }



if ( query.size () >1)
    bShow=true;


cout << listmaxpos << endl;
if ( bShow )
{
 LanguageSettings::load("mythfrontend");

    MythMainWindow *mainWindow = GetMythMainWindow();
    mainWindow->Init();
    gContext->SetMainWindow(mainWindow);
        initKeys();
  runstuff(msg,BElist,becommand);

delete gContext;
}
else
{
  dorestart( becommand,  BElist[0]  );
}
return 0;
}