[mythtv] [PATCH] less crashes when no connection can be made to backend

DanM dan at milkcarton.com
Wed Oct 1 09:34:47 EDT 2003


Tako, tab width is 4, convert tabs to spaces.  For your convience, I've 
corrected and re-attached your patch with each tab turned into 4 spaces.

-dan

Tako Schotanus wrote:

>
> Can you at least tell me what you mean by "fix your indentation"? As 
> it stands your remark is useless to me.
>
> Everything looks good on my end of things, but that's obvious of course.
> So what's wrong? Am I using tabs instead of spaces? The other way 
> around? What?
>
> -Tako
>
> Isaac Richards wrote:
>
>> On Sunday 28 September 2003 09:49 am, Tako Schotanus wrote:
>>  
>>
>>> Some of the changes I made are:
>>>   
>>
>>
>> Fix your indentation, and I'll look at this.  As it stands now, I'd 
>> have to change pretty much every single line you've touched in this 
>> patch, and I don't really want to spend my time doing that.
>>
>> Isaac
>>
>> _______________________________________________
>> mythtv-dev mailing list
>> mythtv-dev at mythtv.org
>> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>>  
>>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>mythtv-dev mailing list
>mythtv-dev at mythtv.org
>http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>  
>

-- 
main(){int j=1234;char t[]=":@abcdefghijklmnopqrstuvwxyz.\n",*i=
"iqgbgxmdzlolyb\nu.pax\nlek.n";char *strchr(const char*,int);
while(*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}

-------------- next part --------------
Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.85
diff -u -2 -r1.85 mythcontext.cpp
--- libs/libmyth/mythcontext.cpp    26 Sep 2003 16:16:41 -0000    1.85
+++ libs/libmyth/mythcontext.cpp    28 Sep 2003 13:04:33 -0000
@@ -107,9 +107,9 @@
 }
 
-void MythContext::ConnectToMasterServer(void)
+bool MythContext::ConnectToMasterServer(void)
 {
     QString server = gContext->GetSetting("MasterServerIP", "localhost");
     int port = gContext->GetNumSetting("MasterServerPort", 6543);
-    ConnectServer(server, port);
+    return ConnectServer(server, port);
 }
 
@@ -136,5 +136,9 @@
             cerr << "You probably should modify the Master Server settings\n";
             cerr << "in the setup program and set the proper IP address.\n";
-            exit(0);
+            MythPopupBox::showOkPopup(mainWindow, tr("connection failure"), tr("Could not connect to backend server"));
+            serverSock->close();
+            delete serverSock;
+            serverSock = NULL;
+            return false;
         }
     }
@@ -143,5 +147,9 @@
     {
         cout << "Could not connect to backend server\n";
-        exit(0);
+        MythPopupBox::showOkPopup(mainWindow, tr("connection failure"), tr("Could not connect to backend server"));
+        serverSock->close();
+        delete serverSock;
+        serverSock = NULL;
+        return false;
     }
 
@@ -158,9 +166,12 @@
 QString MythContext::GetMasterHostPrefix(void)
 {
+    QString ret;
+    
     if (!serverSock)
         ConnectToMasterServer();
 
-    QString ret = QString("myth://%1:%2/").arg(serverSock->peerName())
-                                          .arg(serverSock->peerPort());
+    if (serverSock)
+        ret = QString("myth://%1:%2/").arg(serverSock->peerName())
+                                      .arg(serverSock->peerPort());
     return ret;
 }
@@ -939,29 +950,38 @@
 }
 
-void MythContext::SendReceiveStringList(QStringList &strlist)
+bool MythContext::SendReceiveStringList(QStringList &strlist)
 {
     if (!serverSock)
         ConnectToMasterServer();
 
-    serverSockLock.lock();
-    expectingReply = true;
-
-    WriteStringList(serverSock, strlist);
-    ReadStringList(serverSock, strlist);
-
-    while (strlist[0] == "BACKEND_MESSAGE")
-    {
-        // oops, not for us
-        QString message = strlist[1];
-        QString extra = strlist[2];
-
-        MythEvent me(message, extra);
-        dispatch(me);
-
-        ReadStringList(serverSock, strlist);
-    }
-
-    expectingReply = false;
-    serverSockLock.unlock();
+    if (serverSock)
+    {
+        serverSockLock.lock();
+        expectingReply = true;
+    
+        WriteStringList(serverSock, strlist);
+        bool ok = ReadStringList(serverSock, strlist);
+    
+        while (ok && (strlist[0] == "BACKEND_MESSAGE"))
+        {
+            // oops, not for us
+            QString message = strlist[1];
+            QString extra = strlist[2];
+    
+            MythEvent me(message, extra);
+            dispatch(me);
+    
+            ok = ReadStringList(serverSock, strlist);
+        }
+    
+        expectingReply = false;
+        serverSockLock.unlock();
+        
+        return ok;
+    }
+    else
+    {
+        return false;
+    }
 }
 
@@ -973,23 +993,24 @@
     serverSockLock.lock();
 
-    while (serverSock->bytesAvailable() > 0)
+    while ((serverSock->state() == QSocket::Connected) && (serverSock->bytesAvailable() > 0))
     {
         QStringList strlist;
-        ReadStringList(serverSock, strlist);
-
-        QString prefix = strlist[0];
-        QString message = strlist[1];
-        QString extra = strlist[2];
-
-        if (prefix != "BACKEND_MESSAGE")
-        {
-            cerr << "Received a: " << prefix << " message from the backend\n";
-            cerr << "But I don't know what to do with it.\n";
-        }
-        else
-        {
-            MythEvent me(message, extra);
-            dispatch(me);
-        }
+        if (ReadStringList(serverSock, strlist))
+        {
+            QString prefix = strlist[0];
+            QString message = strlist[1];
+            QString extra = strlist[2];
+    
+            if (prefix != "BACKEND_MESSAGE")
+            {
+                cerr << "Received a: " << prefix << " message from the backend\n";
+                cerr << "But I don't know what to do with it.\n";
+            }
+            else
+            {
+                MythEvent me(message, extra);
+                dispatch(me);
+            }
+        }
     }
 
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.99
diff -u -2 -r1.99 mythcontext.h
--- libs/libmyth/mythcontext.h    20 Sep 2003 01:38:06 -0000    1.99
+++ libs/libmyth/mythcontext.h    28 Sep 2003 13:04:33 -0000
@@ -83,5 +83,5 @@
     QString GetHostName(void) { return m_localhostname; }
 
-    void ConnectToMasterServer(void);
+    bool ConnectToMasterServer(void);
     bool ConnectServer(const QString &hostname, int port);
 
@@ -140,5 +140,5 @@
     void dispatchNow(MythEvent &e);
 
-    void SendReceiveStringList(QStringList &strlist);
+    bool SendReceiveStringList(QStringList &strlist);
 
     QImage *CacheRemotePixmap(const QString &url, bool needevents = true);
Index: libs/libmyth/mythdialogs.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.cpp,v
retrieving revision 1.21
diff -u -2 -r1.21 mythdialogs.cpp
--- libs/libmyth/mythdialogs.cpp    20 Sep 2003 01:38:06 -0000    1.21
+++ libs/libmyth/mythdialogs.cpp    28 Sep 2003 13:04:38 -0000
@@ -213,6 +213,9 @@
                                 ybase, screenheight, hmult);
 
-    setFont(QFont("Arial", (int)(gContext->GetMediumFontSize() * hmult),
-            QFont::Bold));
+    defaultBigFont = QFont("Arial", (int)(gContext->GetBigFontSize() * hmult), QFont::Bold);
+    defaultMediumFont = QFont("Arial", (int)(gContext->GetMediumFontSize() * hmult), QFont::Bold);
+    defaultSmallFont = QFont("Arial", (int)(gContext->GetSmallFontSize() * hmult), QFont::Bold);
+
+    setFont(defaultMediumFont);
     setCursor(QCursor(Qt::BlankCursor));
 
@@ -346,4 +349,7 @@
     setCursor(QCursor(Qt::BlankCursor));
 
+    hpadding = 110;
+    wpadding = 80;
+    
     vbox = new QVBoxLayout(this, (int)(10 * hmult));
 }
@@ -367,4 +373,7 @@
     setCursor(QCursor(Qt::BlankCursor));
 
+    hpadding = 110;
+    wpadding = 80;
+    
     vbox = new QVBoxLayout(this, (int)(10 * hmult));
 
@@ -395,5 +404,73 @@
 }
 
-void MythPopupBox::ShowPopup(int hpadding, int wpadding)
+/*
+ * Adds a label of medium size to the pop-up.
+ *   caption - The text to show in the label
+ * Returns the newly created QLabel
+ */
+QLabel *MythPopupBox::addLabel(QString caption)
+{
+    return addLabel(caption, Medium);
+}
+
+/*
+ * Adds a label of the given size to the pop-up.
+ *   caption - The text to show in the label
+ *   size - The size to use for the caption: Large, Medium or Small.
+ * Returns the newly created QLabel
+ */
+QLabel *MythPopupBox::addLabel(QString caption, LabelSize size)
+{
+    QLabel *label = new QLabel(caption, this);
+    if (size == Large)
+        label->setFont(defaultBigFont);
+    else if (size == Medium)
+        label->setFont(defaultMediumFont);
+    else if (size == Small)
+        label->setFont(defaultSmallFont);
+    label->setMaximumWidth((int)(m_parent->width() / 2));
+    addWidget(label, false);
+    return label;
+}
+
+/*
+ * Adds a button to the pop-up.
+ *   caption - The text to show in the button
+ * Returns the newly created QButton
+ */
+QButton *MythPopupBox::addButton(QString caption)
+{
+    return addButton(caption, this, SLOT(defaultButtonPressedHandler()));
+}
+
+/*
+ * Adds a button to the pop-up.
+ *   caption - The text to show in the button
+ *   target - The target object for the button pressed signal
+ *   slot - The target's method to call when the button is pressed
+ * Returns the newly created QButton
+ */
+QButton *MythPopupBox::addButton(QString caption, QObject *target, const char *slot)
+{
+    MythPushButton *button = new MythPushButton(caption, this);
+    m_parent->connect(button, SIGNAL(pressed()), target, slot);
+    addWidget(button, false);
+    return button;
+}
+
+/*
+ * Show the pop-up
+ */
+void MythPopupBox::ShowPopup()
+{
+    ShowPopup(NULL, NULL);
+}
+
+/*
+ * Show the pop-up
+ *   target - The target object for the ESC pressed signal
+ *   slot - The target's method to call when the ESC key is pressed
+ */
+void MythPopupBox::ShowPopup(QObject *target, const char *slot)
 {
     const QObjectList *objlist = children();
@@ -433,6 +510,6 @@
     maxw += (int)(wpadding * wmult);
 
-    int width = (int)(800 * wmult);
-    int height = (int)(600 * hmult);
+    int width = (int)(m_parent->width() * wmult);
+    int height = (int)(m_parent->height() * hmult);
 
     if (parentWidget())
@@ -448,7 +525,90 @@
     setGeometry(x, y, maxw, poph);
 
+    if (target && slot)
+    {
+        QAccel *popaccel = new QAccel(this);
+        popaccel->connectItem(popaccel->insertItem(m_parent->Key_Escape), target, slot);
+    }
+    
     Show();
 }
 
+/*
+ * Show the modal pop-up
+ * Returns the index of the widget that closed the pop-up
+ */
+int MythPopupBox::ExecPopup()
+{
+    return ExecPopup(this, SLOT(defaultExitHandler()));
+}
+
+/*
+ * Show the modal pop-up
+ *   target - The target object for the ESC pressed signal
+ *   slot - The target's method to call when the ESC key is pressed
+ * Returns the index of the widget that closed the pop-up
+ */
+int MythPopupBox::ExecPopup(QObject *target, const char *slot)
+{
+    ShowPopup(target, slot);
+    return exec();
+}
+
+/*
+ * Handles the signals from buttons that don't have their own slot handler.
+ * Is only useful for modal dialogs
+ */
+void MythPopupBox::defaultButtonPressedHandler()
+{
+    const QObjectList *objlist = children();
+    QObjectListIt it(*objlist);
+    QObject *objs;
+    int i = 0;
+    while ((objs = it.current()) != 0)
+    {
+        ++it;
+        if (objs->isWidgetType())
+        {
+            QWidget *widget = (QWidget *)objs;
+            if (widget->hasFocus())
+                break;
+            i++;
+        }
+    }
+    done(i);
+}
+
+/*
+ * Handles the escape key if no other handler was specified.
+ * Is only useful for modal dialogs
+ */
+void MythPopupBox::defaultExitHandler()
+{
+    done(-1);
+}
+
+void MythPopupBox::showOkPopup(MythMainWindow *parent, QString title, QString message)
+{
+    MythPopupBox popup(parent, title);
+    popup.addLabel(message);
+    QButton *okButton = popup.addButton(tr("OK"));
+    okButton->setFocus();
+    popup.ExecPopup();
+}
+
+bool MythPopupBox::showOkCancelPopup(MythMainWindow *parent, QString title, QString message, bool focusOk)
+{
+    MythPopupBox popup(parent, title);
+    popup.addLabel(message);
+    QButton *okButton = popup.addButton(tr("OK"));
+    QButton *cancelButton = popup.addButton(tr("Cancel"));
+    if (focusOk) {
+        okButton->setFocus();
+    } else {
+        cancelButton->setFocus();
+    }
+    return (popup.ExecPopup() == 1);
+}
+
 MythProgressDialog::MythProgressDialog(const QString &message, int totalSteps)
                   : MythDialog(gContext->GetMainWindow(), "progress", false)
Index: libs/libmyth/mythdialogs.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.h,v
retrieving revision 1.18
diff -u -2 -r1.18 mythdialogs.h
--- libs/libmyth/mythdialogs.h    20 Sep 2003 01:38:06 -0000    1.18
+++ libs/libmyth/mythdialogs.h    28 Sep 2003 13:04:39 -0000
@@ -108,4 +108,6 @@
     int screenwidth, screenheight;
     int xbase, ybase;
+
+    QFont defaultBigFont, defaultMediumFont, defaultSmallFont;
  
     MythMainWindow *m_parent;
@@ -118,4 +120,5 @@
 class MythPopupBox : public MythDialog
 {
+    Q_OBJECT
   public:
     MythPopupBox(MythMainWindow *parent, const char *name = 0);
@@ -126,9 +129,28 @@
     void addWidget(QWidget *widget, bool setAppearance = true);
 
-    void ShowPopup(int hpadding = 0, int wpadding = 0);
+    typedef enum { Large, Medium, Small } LabelSize;
+
+    QLabel *addLabel(QString caption);
+    QLabel *addLabel(QString caption, LabelSize size);
+
+    QButton *addButton(QString caption);
+    QButton *addButton(QString caption, QObject *target, const char *slot);
+
+    void ShowPopup();
+    void ShowPopup(QObject *target, const char *slot);
+    int ExecPopup();
+    int ExecPopup(QObject *target, const char *slot);
+    
+    static void showOkPopup(MythMainWindow *parent, QString title, QString message);
+    static bool showOkCancelPopup(MythMainWindow *parent, QString title, QString message, bool focusOk);
+    
+  protected slots:
+    void defaultButtonPressedHandler();
+    void defaultExitHandler();
 
   private:
     QVBoxLayout *vbox;
     QColor popupForegroundColor;
+    int hpadding, wpadding;
 };
 
Index: libs/libmyth/util.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/util.cpp,v
retrieving revision 1.23
diff -u -2 -r1.23 util.cpp
--- libs/libmyth/util.cpp    20 Sep 2003 01:38:06 -0000    1.23
+++ libs/libmyth/util.cpp    28 Sep 2003 13:04:40 -0000
@@ -84,4 +84,6 @@
     while (socket->waitForMore(5) < 8)
     {
+        if (socket->state() != QSocket::Connected)
+            return false;
         qApp->unlock();
         usleep(50);
Index: libs/libmythtv/remoteutil.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/remoteutil.cpp,v
retrieving revision 1.18
diff -u -2 -r1.18 remoteutil.cpp
--- libs/libmythtv/remoteutil.cpp    20 Sep 2003 01:38:06 -0000    1.18
+++ libs/libmythtv/remoteutil.cpp    28 Sep 2003 13:04:44 -0000
@@ -16,20 +16,22 @@
     QStringList strlist = str;
 
-    gContext->SendReceiveStringList(strlist);
-
-    int numrecordings = strlist[0].toInt();
-
-    vector<ProgramInfo *> *info = new vector<ProgramInfo *>;
-    int offset = 1;
-
-    for (int i = 0; i < numrecordings; i++)
-    {
-        ProgramInfo *pginfo = new ProgramInfo();
-        pginfo->FromStringList(strlist, offset);
-        info->push_back(pginfo);
-
-        offset += NUMPROGRAMLINES;
-    }
-
+    vector<ProgramInfo *> *info = NULL;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        int numrecordings = strlist[0].toInt();
+    
+        info = new vector<ProgramInfo *>;
+        int offset = 1;
+    
+        for (int i = 0; i < numrecordings; i++)
+        {
+            ProgramInfo *pginfo = new ProgramInfo();
+            pginfo->FromStringList(strlist, offset);
+            info->push_back(pginfo);
+    
+            offset += NUMPROGRAMLINES;
+        }
+    }
+    
     return info;
 }
@@ -39,8 +41,9 @@
     QStringList strlist = QString("QUERY_FREESPACE");
 
-    gContext->SendReceiveStringList(strlist);
-
-    totalspace = strlist[0].toInt();
-    usedspace = strlist[1].toInt();
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        totalspace = strlist[0].toInt();
+        usedspace = strlist[1].toInt();
+    }
 }
 
@@ -50,7 +53,9 @@
     pginfo->ToStringList(strlist);
 
-    gContext->SendReceiveStringList(strlist);
-
-    bool exists = strlist[0].toInt();
+    bool exists = false;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        exists = strlist[0].toInt();
+    }
     return exists;
 }
@@ -89,20 +94,22 @@
     QStringList strlist = QString("QUERY_GETALLPENDING");
 
-    gContext->SendReceiveStringList(strlist);
-
-    bool conflicting = strlist[0].toInt();
-    int numrecordings = strlist[1].toInt();
-
-    int offset = 2;
-
-    for (int i = 0; i < numrecordings; i++)
-    {
-        ProgramInfo *pginfo = new ProgramInfo();
-        pginfo->FromStringList(strlist, offset);
-        recordinglist.push_back(pginfo);
-
-        offset += NUMPROGRAMLINES;
-    }
-
+    bool conflicting = false;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        conflicting = strlist[0].toInt();
+        int numrecordings = strlist[1].toInt();
+    
+        int offset = 2;
+    
+        for (int i = 0; i < numrecordings; i++)
+        {
+            ProgramInfo *pginfo = new ProgramInfo();
+            pginfo->FromStringList(strlist, offset);
+            recordinglist.push_back(pginfo);
+    
+            offset += NUMPROGRAMLINES;
+        }
+    }
+    
     return conflicting;
 }
@@ -112,17 +119,18 @@
     QStringList strlist = QString("QUERY_GETALLSCHEDULED");
 
-    gContext->SendReceiveStringList(strlist);
-
-    int numrecordings = strlist[0].toInt();
-    int offset = 1;
-
-    for (int i = 0; i < numrecordings; i++)
-    {
-        ProgramInfo *pginfo = new ProgramInfo();
-        pginfo->FromStringList(strlist, offset);
-        scheduledlist.push_back(pginfo);
-
-        offset += NUMPROGRAMLINES;
-    }
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        int numrecordings = strlist[0].toInt();
+        int offset = 1;
+    
+        for (int i = 0; i < numrecordings; i++)
+        {
+            ProgramInfo *pginfo = new ProgramInfo();
+            pginfo->FromStringList(strlist, offset);
+            scheduledlist.push_back(pginfo);
+    
+            offset += NUMPROGRAMLINES;
+        }
+    }
 }
 
@@ -134,20 +142,22 @@
     pginfo->ToStringList(strlist);
 
-    gContext->SendReceiveStringList(strlist);
-
-    int numrecordings = strlist[0].toInt();
-    int offset = 1;
-
-    vector<ProgramInfo *> *retlist = new vector<ProgramInfo *>;
-
-    for (int i = 0; i < numrecordings; i++)
-    {
-        ProgramInfo *pginfo = new ProgramInfo();
-        pginfo->FromStringList(strlist, offset);
-        retlist->push_back(pginfo);
-
-        offset += NUMPROGRAMLINES;
-    }
-
+    vector<ProgramInfo *> *retlist = NULL;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        int numrecordings = strlist[0].toInt();
+        int offset = 1;
+    
+        retlist = new vector<ProgramInfo *>;
+    
+        for (int i = 0; i < numrecordings; i++)
+        {
+            ProgramInfo *pginfo = new ProgramInfo();
+            pginfo->FromStringList(strlist, offset);
+            retlist->push_back(pginfo);
+    
+            offset += NUMPROGRAMLINES;
+        }
+    }
+    
     return retlist;
 }
@@ -157,11 +167,15 @@
     QStringList strlist = "GET_FREE_RECORDER";
 
-    gContext->SendReceiveStringList(strlist);
-
-    int num = strlist[0].toInt();
-    QString hostname = strlist[1];
-    int port = strlist[2].toInt();
-
-    return new RemoteEncoder(num, hostname, port);
+    RemoteEncoder *encoder = NULL;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        int num = strlist[0].toInt();
+        QString hostname = strlist[1];
+        int port = strlist[2].toInt();
+    
+        encoder = new RemoteEncoder(num, hostname, port);
+    }
+    
+    return encoder;
 }
 
@@ -171,11 +185,15 @@
     pginfo->ToStringList(strlist);
 
-    gContext->SendReceiveStringList(strlist);
-
-    int num = strlist[0].toInt();
-    QString hostname = strlist[1];
-    int port = strlist[2].toInt();
-
-    return new RemoteEncoder(num, hostname, port);
+    RemoteEncoder *encoder = NULL;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        int num = strlist[0].toInt();
+        QString hostname = strlist[1];
+        int port = strlist[2].toInt();
+    
+        encoder = new RemoteEncoder(num, hostname, port);
+    }
+    
+    return encoder;
 }
 
@@ -185,10 +203,14 @@
     strlist << QString("%1").arg(recordernum);
 
-    gContext->SendReceiveStringList(strlist);
-
-    QString hostname = strlist[0];
-    int port = strlist[1].toInt();
-
-    return new RemoteEncoder(recordernum, hostname, port);
+    RemoteEncoder *encoder = NULL;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        QString hostname = strlist[0];
+        int port = strlist[1].toInt();
+    
+        encoder = new RemoteEncoder(recordernum, hostname, port);
+    }
+    
+    return encoder;
 }
 
@@ -215,7 +237,8 @@
     pginfo->ToStringList(strlist);
 
-    gContext->SendReceiveStringList(strlist);
-
-    pginfo->FromStringList(strlist, 0);
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        pginfo->FromStringList(strlist, 0);
+    }
 }
 
@@ -223,6 +246,10 @@
 {
     QStringList strlist = "QUERY_ISRECORDING";
-    gContext->SendReceiveStringList(strlist);
-    return strlist[0].toInt();
+    int result = -1;
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        result = strlist[0].toInt();
+    }
+    return result;
 }
 
@@ -233,22 +260,25 @@
     QString cmd = "QUERY_ISRECORDING";
     QStringList strlist = cmd;
-    gContext->SendReceiveStringList(strlist);
-    int recCount = strlist[0].toInt();
-
-    for (int i = 0, j = 0; j < recCount; i++)
-    {
-        cmd = QString("QUERY_RECORDER %1").arg(i + 1);
-
-        strlist = cmd;
-        strlist << "IS_RECORDING";
-
-        gContext->SendReceiveStringList(strlist);
-        if (strlist[0].toInt())
-        {
-            mask |= 1<<i;
-            j++;       // count active recorder
-        }
-    }
-
+    
+    if (gContext->SendReceiveStringList(strlist))
+    {
+        int recCount = strlist[0].toInt();
+    
+        for (int i = 0, j = 0; j < recCount; i++)
+        {
+            cmd = QString("QUERY_RECORDER %1").arg(i + 1);
+    
+            strlist = cmd;
+            strlist << "IS_RECORDING";
+    
+            gContext->SendReceiveStringList(strlist);
+            if (strlist[0].toInt())
+            {
+                mask |= 1<<i;
+                j++;       // count active recorder
+            }
+        }
+    }
+    
     return mask;
 }
Index: libs/libmythtv/tv_play.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.105
diff -u -2 -r1.105 tv_play.cpp
--- libs/libmythtv/tv_play.cpp    26 Sep 2003 21:32:19 -0000    1.105
+++ libs/libmythtv/tv_play.cpp    28 Sep 2003 13:04:49 -0000
@@ -183,5 +183,7 @@
     {
         RemoteEncoder *testrec = RemoteRequestRecorder();
-
+        if (!testrec)
+            return 0;
+        
         if (!testrec->IsValidRecorder())
         {
@@ -298,4 +300,6 @@
 
     recorder = RemoteGetExistingRecorder(recordernum);
+    if (!recorder)
+        return -1;
 
     if (recorder->IsValidRecorder())
@@ -442,10 +446,11 @@
         {
             recorder = RemoteGetExistingRecorder(playbackinfo);
-            if (!recorder->IsValidRecorder())
+            if (!recorder || !recorder->IsValidRecorder())
             {
                 cerr << "ERROR: couldn't find recorder for in-progress "
                      << "recording\n";
                 nextState = kState_WatchingPreRecorded;
-                delete recorder;
+                if (recorder)
+                    delete recorder;
                 activerecorder = recorder = NULL;
             }
@@ -1171,5 +1176,5 @@
         RemoteEncoder *testrec = RemoteRequestRecorder();
 
-        if (!testrec->IsValidRecorder())
+        if (!testrec || !testrec->IsValidRecorder())
         {
             delete testrec;
Index: programs/mythbackend/mainserver.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/mainserver.cpp,v
retrieving revision 1.82
diff -u -2 -r1.82 mainserver.cpp
--- programs/mythbackend/mainserver.cpp    24 Sep 2003 23:40:00 -0000    1.82
+++ programs/mythbackend/mainserver.cpp    28 Sep 2003 13:04:56 -0000
@@ -171,5 +171,6 @@
 
     QStringList listline;
-    ReadStringList(sock, listline);
+    if (!ReadStringList(sock, listline))
+        return;
     QString line = listline[0];
 
Index: programs/mythbackend/playbacksock.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/playbacksock.cpp,v
retrieving revision 1.15
diff -u -2 -r1.15 playbacksock.cpp
--- programs/mythbackend/playbacksock.cpp    20 Sep 2003 01:38:07 -0000    1.15
+++ programs/mythbackend/playbacksock.cpp    28 Sep 2003 13:04:57 -0000
@@ -34,5 +34,5 @@
 }
 
-void PlaybackSock::SendReceiveStringList(QStringList &strlist)
+bool PlaybackSock::SendReceiveStringList(QStringList &strlist)
 {
     sockLock.lock();
@@ -40,7 +40,7 @@
 
     WriteStringList(sock, strlist);
-    ReadStringList(sock, strlist);
+    bool ok = ReadStringList(sock, strlist);
 
-    while (strlist[0] == "BACKEND_MESSAGE")
+    while (ok && (strlist[0] == "BACKEND_MESSAGE"))
     {
         // oops, not for us
@@ -51,9 +51,11 @@
         gContext->dispatch(me);
 
-        ReadStringList(sock, strlist);
+        ok = ReadStringList(sock, strlist);
     }
 
     expectingreply = false;
     sockLock.unlock();
+    
+    return ok;
 }
 
Index: programs/mythbackend/playbacksock.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/playbacksock.h,v
retrieving revision 1.10
diff -u -2 -r1.10 playbacksock.h
--- programs/mythbackend/playbacksock.h    20 Sep 2003 01:38:07 -0000    1.10
+++ programs/mythbackend/playbacksock.h    28 Sep 2003 13:04:57 -0000
@@ -43,5 +43,5 @@
 
   private:
-    void SendReceiveStringList(QStringList &strlist);
+    bool SendReceiveStringList(QStringList &strlist);
 
     QSocket *sock;
Index: programs/mythfrontend/playbackbox.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/playbackbox.cpp,v
retrieving revision 1.93
diff -u -2 -r1.93 playbackbox.cpp
--- programs/mythfrontend/playbackbox.cpp    20 Sep 2003 01:38:07 -0000    1.93
+++ programs/mythfrontend/playbackbox.cpp    28 Sep 2003 13:05:01 -0000
@@ -100,5 +100,5 @@
     }
 
-    FillList(); 
+    connected = FillList(); 
 
     curTitle = 0;
@@ -110,9 +110,4 @@
     timeformat = gContext->GetSetting("TimeFormat", "h:mm AP");
 
-    bigFont = QFont("Arial", (int)(gContext->GetBigFontSize() * hmult), 
-                    QFont::Bold);
-    medFont = QFont("Arial", (int)(gContext->GetMediumFontSize() * hmult),
-                    QFont::Bold);
-
     nvp = NULL;
     timer = new QTimer(this);
@@ -511,5 +506,8 @@
     int total, used;
     noUpdate = true;
-    RemoteGetFreeSpace(total, used);
+    if (connected)
+        RemoteGetFreeSpace(total, used);
+    else
+        used = total = 1;
     noUpdate = false;
 
@@ -986,5 +984,5 @@
 }
 
-void PlaybackBox::FillList()
+bool PlaybackBox::FillList()
 {
     QString chanid = "";
@@ -1063,4 +1061,6 @@
 
     noUpdate = false;
+    
+    return (infoList != NULL);
 }
 
@@ -1317,5 +1317,5 @@
     delete tvrec;
 
-    FillList();
+    connected = FillList();
     skipUpdate = false;
     update(fullRect);
@@ -1351,5 +1351,5 @@
         curShowing = 0;
         skipNum = 0;
-        FillList();
+        connected = FillList();
     }
     else 
@@ -1359,5 +1359,5 @@
             listCount--;
 
-        FillList();
+        connected = FillList();
 
         if (skipNum < 0)
@@ -1471,26 +1471,24 @@
 
     QString tmpmessage;
-
+    const char *tmpslot;
+    
     switch (types)
     {
-        case 1: case 2: tmpmessage = tr("Yes, get rid of it"); break;
-        case 3: tmpmessage = tr("Yes, AutoExpire"); break;
-        case 4: tmpmessage = tr("Yes, stop recording it"); break;
-        default: tmpmessage = "ERROR ERROR ERROR"; break;
+        case 1: case 2: tmpmessage = tr("Yes, get rid of it"); tmpslot = SLOT(doDelete()); break;
+        case 3: tmpmessage = tr("Yes, AutoExpire"); tmpslot = SLOT(doAutoExpire()); break;
+        case 4: tmpmessage = tr("Yes, stop recording it"); tmpslot = SLOT(doStop()); break;
+        default: tmpmessage = "ERROR ERROR ERROR"; tmpslot = NULL; break;
     }
-    MythPushButton *yesButton = new MythPushButton(tmpmessage, popup);
+    QButton *yesButton = popup->addButton(tmpmessage, this, tmpslot);
 
     switch (types)
     {
-        case 1: tmpmessage = tr("No, I might want to watch it again."); break;
-        case 2: tmpmessage = tr("No, keep it, I changed my mind"); break;
-        case 3: tmpmessage = tr("No, do not AutoExpire"); break;
-        case 4: tmpmessage = tr("No, continue recording it"); break;
-        default: tmpmessage = "ERROR ERROR ERROR"; break;
+        case 1: tmpmessage = tr("No, I might want to watch it again."); tmpslot = SLOT(noDelete()); break;
+        case 2: tmpmessage = tr("No, keep it, I changed my mind"); tmpslot = SLOT(noDelete()); break;
+        case 3: tmpmessage = tr("No, do not AutoExpire"); tmpslot = SLOT(noAutoExpire()); break;
+        case 4: tmpmessage = tr("No, continue recording it"); tmpslot = SLOT(noStop()); break;
+        default: tmpmessage = "ERROR ERROR ERROR"; tmpslot = NULL; break;
     }
-    MythPushButton *noButton = new MythPushButton(tmpmessage, popup);
-
-    popup->addWidget(yesButton, false);
-    popup->addWidget(noButton, false);
+    QButton *noButton = popup->addButton(tmpmessage, this, tmpslot);
 
     if (types == 1 || types == 2)
@@ -1505,25 +1503,5 @@
     }
  
-    popup->ShowPopup(110, 80); 
-
-    if (types == 1 || types == 2)
-    {
-        connect(yesButton, SIGNAL(pressed()), this, SLOT(doDelete()));
-        connect(noButton, SIGNAL(pressed()), this, SLOT(noDelete()));
-    }
-    else if (types == 3)
-    {
-        connect(yesButton, SIGNAL(pressed()), this, SLOT(doAutoExpire()));
-        connect(noButton, SIGNAL(pressed()), this, SLOT(noAutoExpire()));
-    }
-    else if (types == 4)
-    {
-        connect(yesButton, SIGNAL(pressed()), this, SLOT(doStop()));
-        connect(noButton, SIGNAL(pressed()), this, SLOT(noStop()));
-    }
-
-    QAccel *popaccel = new QAccel(popup);
-    popaccel->connectItem(popaccel->insertItem(Key_Escape), this, 
-                          SLOT(doCancel()));
+    popup->ShowPopup(this, SLOT(doCancel()));
 
     expectingPopup = true;
@@ -1551,45 +1529,26 @@
     QDateTime curtime = QDateTime::currentDateTime();
 
-    MythPushButton *playB = new MythPushButton(tr("Play"), popup);
-    connect(playB, SIGNAL(pressed()), this, SLOT(doPlay()));
-    popup->addWidget(playB);
-
-    MythPushButton *tempB;
+    QButton *playButton = popup->addButton(tr("Play"), this, SLOT(doPlay()));
 
     if ((curtime >= program->startts) && (curtime < program->endts))
     {
-        tempB = new MythPushButton(tr("Stop Recording"), popup);
-        connect(tempB, SIGNAL(pressed()), this, SLOT(askStop()));
-        popup->addWidget(tempB);
+        popup->addButton(tr("Stop Recording"), this, SLOT(askStop()));
     }
 
     if (delitem->GetAutoExpireFromRecorded(db))
     {
-        tempB = new MythPushButton(tr("Don't Auto Expire"), popup);
-        connect(tempB, SIGNAL(pressed()), this, SLOT(noAutoExpire()));
-        popup->addWidget(tempB);
+        popup->addButton(tr("Don't Auto Expire"), this, SLOT(noAutoExpire()));
     }
     else
     {
-        tempB = new MythPushButton(tr("Auto Expire"), popup);
-        connect(tempB, SIGNAL(pressed()), this, SLOT(doAutoExpire()));
-        popup->addWidget(tempB);
+        popup->addButton(tr("Auto Expire"), this, SLOT(doAutoExpire()));
     }
 
-    tempB = new MythPushButton(tr("Delete"), popup);
-    connect(tempB, SIGNAL(pressed()), this, SLOT(askDelete()));
-    popup->addWidget(tempB);
-
-    tempB = new MythPushButton(tr("Cancel"), popup);
-    connect(tempB, SIGNAL(pressed()), this, SLOT(doCancel()));
-    popup->addWidget(tempB);
-
-    QAccel *popaccel = new QAccel(popup);
-    popaccel->connectItem(popaccel->insertItem(Key_Escape), this,
-                          SLOT(doCancel()));
+    popup->addButton(tr("Delete"), this, SLOT(askDelete()));
+    popup->addButton(tr("Cancel"), this, SLOT(doCancel()));
 
-    popup->ShowPopup(110, 80);
+    playButton->setFocus();
 
-    playB->setFocus();
+    popup->ShowPopup(this, SLOT(doCancel()));
 
     expectingPopup = true;
@@ -1607,36 +1566,27 @@
 
     QString descrip = program->description;
-    descrip = cutDownString(descrip, &medFont, (int)(width() / 2));
+    descrip = cutDownString(descrip, &defaultMediumFont, (int)(width() / 2));
     QString titl = program->title;
-    titl = cutDownString(titl, &bigFont, (int)(width() / 2));
+    titl = cutDownString(titl, &defaultBigFont, (int)(width() / 2));
 
     if (message.stripWhiteSpace().length() > 0)
     {
-        QLabel *msg = new QLabel(message, popup);
-        QLabel *filler1 = new QLabel("", popup);
-        popup->addWidget(msg, false);
-        popup->addWidget(filler1, false);
+        popup->addLabel(message);
+        popup->addLabel("");
     }
 
-    QLabel *title = new QLabel(program->title, popup);
-    title->setFont(bigFont);
-    title->setMaximumWidth((int)(width() / 2));
-    popup->addWidget(title, false);
+    QLabel *title = popup->addLabel(program->title, MythPopupBox::Large);
 
     if ((program->subtitle).stripWhiteSpace().length() > 0)
     {
-        QLabel *subtitle = new QLabel("\"" + program->subtitle + "\"", popup);
-        popup->addWidget(subtitle, false);
+        popup->addLabel("\"" + program->subtitle + "\"");
     }
 
-    QLabel *times = new QLabel(timedate, popup);
-    popup->addWidget(times, false);
+    popup->addLabel(timedate);
 
     if (message2.stripWhiteSpace().length() > 0)
     {
-        QLabel *filler2 = new QLabel("", popup);
-        QLabel *msg2 = new QLabel(message2, popup);
-        popup->addWidget(filler2, false);
-        popup->addWidget(msg2, false);
+        popup->addLabel("");
+        popup->addLabel(message2);
     }
 }
@@ -1913,5 +1863,5 @@
             if (QDateTime::currentDateTime() > lastUpdateTime.addSecs(1))
             {
-                FillList();      
+                connected = FillList();      
                 update(fullRect);
             }
Index: programs/mythfrontend/playbackbox.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/playbackbox.h,v
retrieving revision 1.31
diff -u -2 -r1.31 playbackbox.h
--- programs/mythfrontend/playbackbox.h    20 Sep 2003 01:38:07 -0000    1.31
+++ programs/mythfrontend/playbackbox.h    28 Sep 2003 13:05:02 -0000
@@ -73,5 +73,5 @@
 
   private:
-    void FillList(void);
+    bool FillList(void);
     void UpdateProgressBar(void);
 
@@ -88,4 +88,5 @@
     bool noUpdate;
     bool pageDowner;
+    bool connected;
     ProgramInfo *curitem;
     ProgramInfo *delitem;
@@ -172,6 +173,4 @@
 
     bool expectingPopup;
-
-    QFont bigFont, medFont;
 };
 


More information about the mythtv-dev mailing list