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

Tako Schotanus quintesse at palacio-cristal.com
Sun Sep 28 16:49:50 EDT 2003


Some of the changes I made are:

-1- MythContext::ConnectServer() will not exit() anymore when it can't 
make a connection to the backend but will pop up a message telling the 
user it couldn't connect to the backend . This was of course the easy part.
-2- ReadStringList() was returning a boolean to indicate if it was able 
to retrieve the requested information but nobody was checking the 
result. (Not having a connection will return false now due to item #1)
-3- Made SendReceiveStringList() return a boolean as well.
-4- Added a number of checks in all kinds of places to make sure that a 
failed call to SendReceiveStringList() doesn't crash the frontend 
anymore, but will continue in in a correct state.
-5- Added the completely redesigned code of the rejected MythSimplePopup 
patch I sent last time. Simple helper methods like addLabel() and 
addButton() are now part of MythPopupBox.
-6- Added static helper methods to MythPopupBox to show simple Ok en 
Ok/Cancel message boxes (used in the code for item #1).

The code is also more robust if the connection fails in the middle of  
an action but unfortunately I haven't been able yet to make it pop up a 
message saying something like "the connection to the backend was lost" 
while watching a recording or live tv for example. Maybe if Isaac can 
give some hints/tips I can even put that in. (The code I have now (which 
is _not_ included in this patch of course) will change a crash into an 
endless loop, well in that case I prefer a crash ;-).

Cheers,
 -Tako


PS: Isaac, if you look at the code needed to make showOkCancelPopup() 
you'll see how simple it can be to make a modal diag with the new helper 
functions (a non-modal dialog is only slighly more work):

    MythPopupBox popup(parent, title);
    popup.addLabel(message);
    QButton *okButton = popup.addButton(tr("OK"));
    QButton *cancelButton = popup.addButton(tr("Cancel"));
    return popup.ExecPopup();

I think this will come a long way to fixing the problem that you 
couldn't just put any widget you wanted in the dialog. In the new way 
you can just choose between using addWidget() or one of the helper 
methods. Of course the helper methods are _extremely_ limited, but if 
they're sufficient for 90% of the cases they could still prove their worth.


-------------- 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