Example #1
0
// Called by libretroshare through notifyQt to display the peer's status
//
void FriendsDialog::updateStatusString(const QString& peer_id, const QString& status_string)
{
#ifdef FRIENDS_DEBUG
    std::cerr << "FriendsDialog: received group chat typing info. updating gui." << std::endl ;
#endif

    QString status = QString::fromUtf8(rsPeers->getPeerName(peer_id.toStdString()).c_str()) + " " + tr(status_string.toAscii());
    ui.statusStringLabel->setText(status) ; // displays info for 5 secs.

    QTimer::singleShot(5000,this,SLOT(resetStatusBar())) ;
}
Example #2
0
void ChatWidget::updateStatusString(const QString &statusMask, const QString &statusString)
{
	ui->statusLabel->setText(QString(statusMask).arg(tr(statusString.toAscii()))); // displays info for 5 secs.
	ui->typingpixmapLabel->setPixmap(QPixmap(":images/typing.png") );

	if (statusString == "is typing...") {
		typing = true;

		emit infoChanged(this);
	}

	QTimer::singleShot(5000, this, SLOT(resetStatusBar())) ;
}
Example #3
0
/** Default constructor */
PopupChatDialog::PopupChatDialog(const std::string &id, const QString &name, QWidget *parent, Qt::WFlags flags)
  : QWidget(parent, flags), dialogId(id), dialogName(name),
    lastChatTime(0), lastChatName("")
    
{
  /* Invoke Qt Designer generated QObject setup routine */
  ui.setupUi(this);

  newMessages = false;
  typing = false;
  m_manualDelete = false;
  peerStatus = 0;

  last_status_send_time = 0 ;
  chatStyle.setStyleFromSettings(ChatStyle::TYPE_PRIVATE);

  /* Hide or show the frames */
  showAvatarFrame(PeerSettings->getShowAvatarFrame(dialogId));
  ui.infoframe->setVisible(false);
  ui.statusmessagelabel->hide();

  connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool)));

  connect(ui.sendButton, SIGNAL(clicked( ) ), this, SLOT(sendChat( ) ));
  connect(ui.addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile()));

  connect(ui.textboldButton, SIGNAL(clicked()), this, SLOT(setFont()));  
  connect(ui.textunderlineButton, SIGNAL(clicked()), this, SLOT(setFont()));  
  connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(setFont()));
  connect(ui.attachPictureButton, SIGNAL(clicked()), this, SLOT(addExtraPicture()));
  connect(ui.fontButton, SIGNAL(clicked()), this, SLOT(getFont())); 
  connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
  connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget()));
  connect(ui.actionSave_Chat_History, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
  connect(ui.actionClearOfflineMessages, SIGNAL(triggered()), this, SLOT(clearOfflineMessages()));


  connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int)));
  connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&)));

  connect(ui.chattextEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint)));

  // Create the status bar
  resetStatusBar();

  ui.textboldButton->setIcon(QIcon(QString(":/images/edit-bold.png")));
  ui.textunderlineButton->setIcon(QIcon(QString(":/images/edit-underline.png")));
  ui.textitalicButton->setIcon(QIcon(QString(":/images/edit-italic.png")));
  ui.fontButton->setIcon(QIcon(QString(":/images/fonts.png")));
  ui.emoteiconButton->setIcon(QIcon(QString(":/images/emoticons/kopete/kopete020.png")));
  
  ui.textboldButton->setCheckable(true);
  ui.textunderlineButton->setCheckable(true);
  ui.textitalicButton->setCheckable(true);

  setAcceptDrops(true);
  ui.chattextEdit->setAcceptDrops(false);

  QMenu * toolmenu = new QMenu();
  toolmenu->addAction(ui.actionClear_Chat_History);
  toolmenu->addAction(ui.actionDelete_Chat_History);
  toolmenu->addAction(ui.actionSave_Chat_History);
  toolmenu->addAction(ui.actionClearOfflineMessages);
  toolmenu->addAction(ui.actionMessageHistory);
  //toolmenu->addAction(ui.action_Disable_Emoticons);
  ui.pushtoolsButton->setMenu(toolmenu);

  mCurrentColor.setNamedColor(PeerSettings->getPrivateChatColor(dialogId));
  mCurrentFont.fromString(PeerSettings->getPrivateChatFont(dialogId));

  colorChanged(mCurrentColor);
  fontChanged(mCurrentFont);

  updateAvatar() ;
  updatePeerAvatar(id) ;

  // load settings
  processSettings(true);

  // load style
  PeerSettings->getStyle(dialogId, "PopupChatDialog", style);

  // initialize first status
  StatusInfo peerStatusInfo;
  // No check of return value. Non existing status info is handled as offline.
  rsStatus->getStatus(dialogId, peerStatusInfo);
  updateStatus(QString::fromStdString(dialogId), peerStatusInfo.status);

  StatusInfo ownStatusInfo;
  if (rsStatus->getOwnStatus(ownStatusInfo)) {
    updateStatus(QString::fromStdString(ownStatusInfo.id), ownStatusInfo.status);
  }

  // initialize first custom state string
  QString customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(dialogId).c_str());
  updatePeersCustomStateString(QString::fromStdString(dialogId), customStateString);

  if (Settings->valueFromGroup("Chat", QString::fromUtf8("PrivateChat_History"), true).toBool()) {
      historyKeeper.init(QString::fromStdString(RsInit::RsProfileConfigDirectory()) + "/chat_" + QString::fromStdString(dialogId) +  ".xml");

      // get offline chat messages
      std::list<ChatInfo> offlineChat;
      std::list<ChatInfo>::iterator offineChatIt;
      rsMsgs->getPrivateChatQueueCount(false) && rsMsgs->getPrivateChatQueue(false, dialogId, offlineChat);

      QList<IMHistoryItem> historyItems;
      int messageCount = Settings->getPrivateChatHistoryCount();
      if (messageCount > 0) {
          historyKeeper.getMessages(historyItems, messageCount);
      }
      foreach(IMHistoryItem item, historyItems) {
          for(offineChatIt = offlineChat.begin(); offineChatIt != offlineChat.end(); offineChatIt++) {
              /* are they public? */
              if ((offineChatIt->chatflags & RS_CHAT_PRIVATE) == 0) {
                  /* this should not happen */
                  continue;
              }

              QDateTime sendTime = QDateTime::fromTime_t(offineChatIt->sendTime);
              QString message = QString::fromStdWString(offineChatIt->msg);

              if (IMHistoryKeeper::compareItem(item, false, offineChatIt->rsid, sendTime, message)) {
                  // don't show offline message out of the history
                  break;
              }
          }

          if (offineChatIt == offlineChat.end()) {
              addChatMsg(item.incoming, item.id, item.name, item.sendTime, item.recvTime, item.messageText, TYPE_HISTORY, false);
          }
      }
  }
/** Default constructor */
PopupChatDialog::PopupChatDialog(std::string id, std::string name, 
				QWidget *parent, Qt::WFlags flags)
  : QMainWindow(parent, flags), dialogId(id), dialogName(name),
    lastChatTime(0), lastChatName("")
    
{
  /* Invoke Qt Designer generated QObject setup routine */
  ui.setupUi(this);

  RshareSettings config;
  config.loadWidgetInformation(this);
  
  loadEmoticons();
  
  last_status_send_time = 0 ;
  styleHtm = ":/qss/chat/default.htm";
  
  /* Hide Avatar frame */
  showAvatarFrame(false);

  connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool)));

  connect(ui.actionAvatar, SIGNAL(triggered()),this, SLOT(getAvatar()));

  connect(ui.chattextEdit, SIGNAL(textChanged ( ) ), this, SLOT(checkChat( ) ));
  
  connect(ui.sendButton, SIGNAL(clicked( ) ), this, SLOT(sendChat( ) ));
  connect(ui.addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile()));

  connect(ui.textboldButton, SIGNAL(clicked()), this, SLOT(setFont()));  
  connect(ui.textunderlineButton, SIGNAL(clicked()), this, SLOT(setFont()));  
  connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(setFont()));
  connect(ui.fontButton, SIGNAL(clicked()), this, SLOT(getFont())); 
  connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
  connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget()));
  connect(ui.styleButton, SIGNAL(clicked()), SLOT(changeStyle()));

  connect(ui.textBrowser, SIGNAL(anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &)));

  // Create the status bar
  resetStatusBar() ;

  ui.textBrowser->setOpenExternalLinks ( false );
  ui.textBrowser->setOpenLinks ( false );

  QString title = QString::fromStdString(name) + " :" + tr(" RetroShare - Encrypted Chat")  ;
  setWindowTitle(title);
  
  //set the default avatar
  //ui.avatarlabel->setPixmap(QPixmap(":/images/retrosharelogo1.png"));
  
  setWindowIcon(QIcon(QString(":/images/rstray3.png")));
  
  ui.textboldButton->setIcon(QIcon(QString(":/images/edit-bold.png")));
  ui.textunderlineButton->setIcon(QIcon(QString(":/images/edit-underline.png")));
  ui.textitalicButton->setIcon(QIcon(QString(":/images/edit-italic.png")));
  ui.fontButton->setIcon(QIcon(QString(":/images/fonts.png")));
  ui.emoteiconButton->setIcon(QIcon(QString(":/images/emoticons/kopete/kopete020.png")));
  ui.styleButton->setIcon(QIcon(QString(":/images/looknfeel.png")));
  
  ui.textboldButton->setCheckable(true);
  ui.textunderlineButton->setCheckable(true);
  ui.textitalicButton->setCheckable(true);

  setAcceptDrops(true);
  ui.chattextEdit->setAcceptDrops(false);
  
  /*Disabled style Button when will switch chat style RetroShare will crash need to be fix */
  //ui.styleButton->setEnabled(false);
   
  /*QMenu * fontmenu = new QMenu();
  fontmenu->addAction(ui.actionBold);
  fontmenu->addAction(ui.actionUnderline);
  fontmenu->addAction(ui.actionItalic);
  fontmenu->addAction(ui.actionStrike);
  ui.fontButton->setMenu(fontmenu);*/
  
  mCurrentColor = Qt::black;
  mCurrentFont = QFont("Comic Sans MS", 10);

  colorChanged(mCurrentColor);
  setFont();

  updateAvatar() ;
  updatePeerAvatar(id) ;
}
void PopupChatDialog::addChatMsg(ChatInfo *ci)
{
	bool offline = true;

	{
	  RsPeerDetails detail;
	  if (!rsPeers->getPeerDetails(dialogId, detail))
	  {
#ifdef CHAT_DEBUG 
		std::cerr << "WARNING CANNOT GET PEER INFO!!!!" << std::endl;
#endif
	  }
	  else if (detail.state & RS_PEER_STATE_CONNECTED)
	  {
	    offline = false;
	  }
	}

	if (offline)
	{
	    	QString offlineMsg = "<br>\n<span style=\"color:#1D84C9\"><strong> ----- PEER OFFLINE (Chat will be lost) -----</strong></span> \n<br>";
		ui.textBrowser->setHtml(ui.textBrowser->toHtml() + offlineMsg);
	}
	

        QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]";
        QString name = QString::fromStdString(ci ->name);        
        QString message = QString::fromStdWString(ci -> msg);

	//replace http:// and www. with <a href> links
	QRegExp rx("(http://[^ <>]*)|(www\\.[^ <>]*)");
	int count = 0;
	int pos = 100; //ignor the first 100 charater because of the standard DTD ref
	while ( (pos = rx.indexIn(message, pos)) != -1 ) {
	    count ++;
	    //we need to look ahead to see if it's already a well formed link
	    if (message.mid(pos - 6, 6) != "href=\"" && message.mid(pos - 6, 6) != "href='" && message.mid(pos - 6, 6) != "ttp://" ) {
		QString tempMessg = message.left(pos) + "<a href=\"" + rx.cap(count) + "\">" + rx.cap(count) + "</a>" + message.mid(pos + rx.matchedLength(), -1);
		message = tempMessg;
	    }
	    pos += rx.matchedLength() + 15;
	}

#ifdef CHAT_DEBUG
std::cout << "PopupChatDialog:addChatMsg message : " << message.toStdString() << std::endl;
#endif


        /*QHashIterator<QString, QString> i(smileys);
	while(i.hasNext())
	{
		i.next();
		message.replace(i.key(), "<img src=\"" + i.value() + "\">");
	}*/

	QHashIterator<QString, QString> i(smileys);
	while(i.hasNext())
	{
		i.next();
		foreach(QString code, i.key().split("|"))
			message.replace(code, "<img src=\"" + i.value() + "\" />");
	}
	history /*<< nickColor << color << font << fontSize*/ << timestamp << name << message;
	
	QString formatMsg = loadEmptyStyle()/*.replace(nickColor)
				    .replace(color)
				    .replace(font)
				    .replace(fontSize)*/
				    .replace("%timestamp%", timestamp)
                    		    .replace("%name%", name)
				    .replace("%message%", message);

	ui.textBrowser->setHtml(ui.textBrowser->toHtml() + formatMsg + "\n");
	
	QTextCursor cursor = ui.textBrowser->textCursor();
	cursor.movePosition(QTextCursor::End);
	ui.textBrowser->setTextCursor(cursor);

	if(ci->chatflags & RS_CHAT_AVATAR_AVAILABLE)
	{
	   std::cerr << "received msg saying an avatar for peer " << ci->rsid << " is available." << std::endl ;
	   updatePeerAvatar(ci->rsid) ;
	}
	resetStatusBar() ;
}
// Called by libretroshare through notifyQt to display the peer's status
//
void PopupChatDialog::updateStatusString(const QString& status_string)
{
	statusBar()->showMessage(status_string,5000) ; // displays info for 5 secs.

	QTimer::singleShot(5000,this,SLOT(resetStatusBar())) ;
}
Example #7
0
ChatWidget::ChatWidget(QWidget *parent) :
	QWidget(parent), ui(new Ui::ChatWidget)
{
	ui->setupUi(this);

	newMessages = false;
	typing = false;
	peerStatus = 0;
	isChatLobby = false;
	firstShow = true;
	inChatCharFormatChanged = false;

	lastStatusSendTime = 0 ;

	connect(ui->sendButton, SIGNAL(clicked()), this, SLOT(sendChat()));
	connect(ui->addFileButton, SIGNAL(clicked()), this , SLOT(addExtraFile()));

	connect(ui->textboldButton, SIGNAL(clicked()), this, SLOT(setFont()));
	connect(ui->textunderlineButton, SIGNAL(clicked()), this, SLOT(setFont()));
	connect(ui->textitalicButton, SIGNAL(clicked()), this, SLOT(setFont()));
	connect(ui->attachPictureButton, SIGNAL(clicked()), this, SLOT(addExtraPicture()));
	connect(ui->colorButton, SIGNAL(clicked()), this, SLOT(chooseColor()));
	connect(ui->emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget()));
	connect(ui->actionSaveChatHistory, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
	connect(ui->actionClearChatHistory, SIGNAL(triggered()), this, SLOT(clearChatHistory()));
	connect(ui->actionDeleteChatHistory, SIGNAL(triggered()), this, SLOT(deleteChatHistory()));
	connect(ui->actionMessageHistory, SIGNAL(triggered()), this, SLOT(messageHistory()));
	connect(ui->actionChooseFont, SIGNAL(triggered()), this, SLOT(chooseFont()));
	connect(ui->actionResetFont, SIGNAL(triggered()), this, SLOT(resetFont()));

	connect(ui->hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));

	connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int)));
	connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&)));

	connect(ui->textBrowser, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));

	connect(ui->chatTextEdit, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint)));
	// reset text and color after removing all characters from the QTextEdit and after calling QTextEdit::clear
	connect(ui->chatTextEdit, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(chatCharFormatChanged()));

	ui->infoFrame->setVisible(false);
	ui->statusMessageLabel->hide();

	setAcceptDrops(true);
	ui->chatTextEdit->setAcceptDrops(false);
	ui->hashBox->setDropWidget(this);
	ui->hashBox->setAutoHide(true);

	QMenu *menu = new QMenu();
	menu->addAction(ui->actionChooseFont);
	menu->addAction(ui->actionResetFont);
	ui->fontButton->setMenu(menu);

	menu = new QMenu();
	menu->addAction(ui->actionClearChatHistory);
	menu->addAction(ui->actionDeleteChatHistory);
	menu->addAction(ui->actionSaveChatHistory);
	menu->addAction(ui->actionMessageHistory);
	ui->pushtoolsButton->setMenu(menu);

	ui->chatTextEdit->installEventFilter(this);

//#if QT_VERSION < 0x040700
	// embedded images are not supported before QT 4.7.0
	ui->attachPictureButton->setVisible(false);
//#endif

	resetStatusBar();
}
Example #8
0
void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType)
{
#ifdef CHAT_DEBUG
	std::cout << "ChatWidget::addChatMsg message : " << message.toStdString() << std::endl;
#endif

	unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_OPTIMIZE;
	unsigned int formatFlag = 0;

	// embed smileys ?
	if (Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_PrivatChat"), true).toBool()) {
		formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
	}

	// Always fix colors
	formatTextFlag |= RSHTML_FORMATTEXT_FIX_COLORS;
	qreal desiredContrast = Settings->valueFromGroup("Chat", "MinimumContrast", 4.5).toDouble();
	QColor backgroundColor = ui->textBrowser->palette().base().color();

	// Remove font name, size, bold, italics?
	if (!Settings->valueFromGroup("Chat", "EnableCustomFonts", true).toBool()) {
		formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY;
	}
	if (!Settings->valueFromGroup("Chat", "EnableCustomFontSize", true).toBool()) {
		formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_SIZE;
	}
	if (!Settings->valueFromGroup("Chat", "EnableBold", true).toBool()) {
		formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT;
	}
	if (!Settings->valueFromGroup("Chat", "EnableItalics", true).toBool()) {
		formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_STYLE;
	}

	ChatStyle::enumFormatMessage type;
	if (chatType == TYPE_OFFLINE) {
		type = ChatStyle::FORMATMSG_OOUTGOING;
	} else if (chatType == TYPE_SYSTEM) {
		type = ChatStyle::FORMATMSG_SYSTEM;
	} else if (chatType == TYPE_HISTORY) {
		type = incoming ? ChatStyle::FORMATMSG_HINCOMING : ChatStyle::FORMATMSG_HOUTGOING;
	} else {
		type = incoming ? ChatStyle::FORMATMSG_INCOMING : ChatStyle::FORMATMSG_OUTGOING;
	}

	if (chatType == TYPE_SYSTEM) {
		formatFlag |= CHAT_FORMATMSG_SYSTEM;
	}

	QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast);
	QString formatMsg = chatStyle.formatMessage(type, name, incoming ? sendTime : recvTime, formattedMessage, formatFlag);

	ui->textBrowser->append(formatMsg);

	resetStatusBar();

	if (incoming && chatType == TYPE_NORMAL) {
		emit newMessage(this);

		if (!isActive()) {
			newMessages = true;
		}

		emit infoChanged(this);
	}
}
Example #9
0
void MainWindow::OnMenuCrawlTimer(wxTimerEvent & event)
{
	// our crawl timer has triggered, time to gets goin'

	static const std::string clStr("\r");
	static const std::string eolStr("\n");

	// wake up the device.
	DRUID::SerialUIUserPtr serial_user = connection->serialUser();
	serial_user->send(eolStr);
	// PLATFORM_SLEEP(1);


	if(connection->ping(3, false))
	{
		DRUID4ARDUINO_DEBUG2("Device seems to be alive on ", serial_port);

		//= ;
		std::string inBuf(serial_user->incomingBuffer());

		std::string name;
		std::string::iterator findIter = std::search(inBuf.begin(), inBuf.end(),
				clStr.begin(), clStr.end());

		if (findIter == inBuf.end())
		{
			findIter = std::search(inBuf.begin(), inBuf.end(),
				eolStr.begin(), eolStr.end());
		}

		if (findIter != inBuf.end()) {

			// copy the newly arrived message to last_message
			name.reserve(findIter - inBuf.begin());
			std::copy(inBuf.begin(), findIter, std::back_inserter(name));
		} else {
			name = inBuf;
		}

		prog_name = DRUID_STDSTRING_TOWX(name);
		resetStatusBar();

	} else {

		wxString errMsg(wxT("No response to ping for 3 seconds on "));
		errMsg += DRUID_STDSTRING_TOWX(serial_port);
		SetStatusText(errMsg);
	}



	// parse the menu
	if (serial_user->isConnected())
	{



		resetSUIWindows();
		if (topLevelMenu)
		{
			// clear out the window menu and its callbacks

			for (unsigned int elementId=MAINWINDOW_DYNAMICMENU_ELEMENTID_START;
					elementId < menu_id_counter; elementId++)
			{
				this->Disconnect(elementId, wxEVT_COMMAND_MENU_SELECTED);
			}

			for (unsigned int i=0; i < topLevelMenu->size(); i++)
			{
				// TODO: must we destroy the returned wxMenuItem?
				deviceMenu->Remove(deviceMenu->FindItemByPosition(0));
			}


		}

		parser.setControlStrings(serial_user->enterProgramMode());
		executing_request = true;
		topLevelMenu = parser.crawl(serial_user);

		if (topLevelMenu)
		{
			// ok, we have our menu structure
			parser.dumpMenus();
			buildAllDeviceMenus(topLevelMenu);

		} else {
			// TODO:FIXME return error
			currentlyEnabledSUIWindown()->setError(wxT("Parser could not crawl menus\r\nEnsure a valid SerialUI device is connected."));
			SetStatusText(wxT("Parser could not crawl menus"));
		}

		serial_user->clear();
		executing_request = false;
		pingTimer->Start(200, false);
	} else {
		SetStatusText(wxT("Serial connection failure"));
	}


}
Example #10
0
void MainWindow::doReInit()
{
	static DRUID::ConnectionPackagePtr nullConnection;

	resetStatusBar();

	trackedstate->clearDisplay();

	if (automatic_update_checks && (rand() % 127) > 109)
		availableUpdateCheck(true);



	// if we already have a connection, close that down and come back later
	if (connection)
	{
		pingTimer->Stop();
		connection->destroy();
		connection = nullConnection;

		SetStatusText(wxT("Closing current connection"));
		autoInitTimer->Start(MAINWINDOW_CONNECTION_CLOSE_DELAY_MS, true);

		return;

	}


	// no matter what, if we get here we (no longer?) have a connection and
	// need to init one...
	if (!loadConfig())
	{
		// first time use
		if (! doGetSettings(true))
		{
			currentlyEnabledSUIWindown()->setError(wxT("Did not specify serial port, please do so prior to initializing."));
			SetStatusText(wxT("Could not automatically set serial port"));
			return;

		}

	}

	// figure out--or request--the port to connect to
	DRUID::SerialEnumerator sEnumerator;

	if (serial_port.size() && sEnumerator.portExists(serial_port))
	{
		DRUID4ARDUINO_DEBUG("Connecting");
		wxString connMsg(wxT("Connecting to "));
		connMsg += DRUID_STDSTRING_TOWX(serial_port);
		SetStatusText(connMsg);
	} else {

		DRUID::PortNameList ports = sEnumerator.listPorts();

		if (! ports.size())
		{
			currentlyEnabledSUIWindown()->setError(wxT("Cannot automatically determine serial port -- specify please."));
			SetStatusText(wxT("Could not automatically set serial port"));
			return;
		} else if (ports.size() > 1)
		{
			currentlyEnabledSUIWindown()->setError(wxT("Cannot automatically determine serial port -- multiple options available, please select."));

			SetStatusText(wxT("Could not automatically set serial port"));

		} else {
			// 1 port avail... try that one.
			serial_port = ports[0];
			std::string statusTxt("Automatic connection to port ");
			statusTxt += serial_port;
			SetStatusText(DRUID_STDSTRING_TOWX(statusTxt));
		}
	}


	// ok, actually get the connection
	connection = DRUID::Util::getConnection(baud_rate, serial_port);

	if (! connection)
	{
		currentlyEnabledSUIWindown()->setError(wxT("Could not create new connection package"));
		DRUID4ARDUINO_DEBUG("Could not create new connection package");
		SetStatusText(wxT("Could not create new connection package"));
		return;
	}

	if (! connection->active())
	{

		wxString errMsg(wxT("Could not connect to "));
		errMsg += DRUID_STDSTRING_TOWX(serial_port);
		errMsg += wxT("\r\nEnsure a valid SerialUI device is connected, and confirm settings.");
		currentlyEnabledSUIWindown()->setError(errMsg);
		SetStatusText(errMsg);
		return;

	}

	// we have an active connection now


	crawlMenusTimer->Start(MAINWINDOW_CONNECTION_STARTCRAWL_DELAY_MS, true);


	return;
}