Server::Server(QWidget *parent) : QDialog(parent), tcpServer(0), networkSession(0) { statusLabel = new QLabel; quitButton = new QPushButton(tr("Quit")); quitButton->setAutoDefault(false); QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { // Get saved network configuration QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); // If the saved network configuration is not currently discovered use the system default QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } networkSession = new QNetworkSession(config, this); connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened())); statusLabel->setText(tr("Opening network session.")); networkSession->open(); } else { sessionOpened(); } fortunes << tr("all in on this"); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); setWindowTitle(tr("Fortune Server")); }
void Roster::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza) { if (AStanza.id() == FDelimRequestId) { FDelimRequestId.clear(); QString groupDelim = ROSTER_GROUP_DELIMITER; if (AStanza.type() == "result") { groupDelim = AStanza.firstElement("query",NS_JABBER_PRIVATE).firstChildElement("roster").text(); if (groupDelim.isEmpty()) { groupDelim = ROSTER_GROUP_DELIMITER; LOG_STRM_INFO(streamJid(),QString("Saving default roster group delimiter on server, delimiter='%1'").arg(groupDelim)); Stanza delim("iq"); delim.setType("set").setId(FStanzaProcessor->newId()); QDomElement elem = delim.addElement("query",NS_JABBER_PRIVATE); elem.appendChild(delim.createElement("roster",NS_STORAGE_GROUP_DELIMITER)).appendChild(delim.createTextNode(groupDelim)); FStanzaProcessor->sendStanzaOut(AStreamJid,delim); } else { LOG_STRM_INFO(streamJid(),QString("Roster group delimiter loaded, delimiter='%1'").arg(groupDelim)); } } else { LOG_STRM_WARNING(streamJid(),QString("Failed to load roster group delimiter: %1").arg(XmppStanzaError(AStanza).condition())); } setGroupDelimiter(groupDelim); requestRosterItems(); } else if (AStanza.id() == FOpenRequestId) { FOpenRequestId.clear(); if (AStanza.type() == "result") { LOG_STRM_INFO(streamJid(),"Roster items loaded"); processItemsElement(AStanza.firstElement("query",NS_JABBER_ROSTER),true); FOpened = true; emit opened(); } else { LOG_STRM_WARNING(streamJid(),QString("Failed to load roster items: %1").arg(XmppStanzaError(AStanza).condition())); FXmppStream->abort(XmppError(IERR_ROSTER_REQUEST_FAILED)); } } }
void Foam::IOstream::print(Ostream& os) const { os << "IOstream: " << "Version " << version_ << ", format "; switch (format_) { case ASCII: os << "ASCII"; break; case BINARY: os << "BINARY"; break; } os << ", line " << lineNumber(); if (opened()) { os << ", OPENED"; } if (closed()) { os << ", CLOSED"; } if (good()) { os << ", GOOD"; } if (eof()) { os << ", EOF"; } if (fail()) { os << ", FAIL"; } if (bad()) { os << ", BAD"; } os << endl; }
bool Socket::wait(unsigned mask, int seconds) const { ASSERT(opened()); fd_set readSet; fd_set writeSet; fd_set exceptSet; fd_set* readSetUse = NULL; fd_set* writeSetUse = NULL; fd_set* exceptSetUse = NULL; #ifdef _WIN32 #pragma warning(push) #pragma warning(disable:4127) #endif if (mask & MASK_READ) { readSetUse = &readSet; FD_ZERO(readSetUse); FD_SET(m_socket, readSetUse); } if (mask & MASK_WRITE) { writeSetUse = &writeSet; FD_ZERO(writeSetUse); FD_SET(m_socket, writeSetUse); } if (mask & MASK_EXCEPT) { exceptSetUse = &exceptSet; FD_ZERO(exceptSetUse); FD_SET(m_socket, exceptSetUse); } #ifdef _WIN32 #pragma warning(pop) #endif timeval timeoutVal; timeoutVal.tv_sec = seconds; timeoutVal.tv_usec = 0; timeval* const timeoutPtr = seconds < 0 ? NULL : &timeoutVal; const int result = select( m_socket + 1, readSetUse, writeSetUse, exceptSetUse, timeoutPtr ); return result > 0; }
const char* Socket::hostname() const { if (!opened()) { return NULL; } sockaddr_in host; socklen_t hostSize = sizeof(host); sockaddr* const hostPtr = reinterpret_cast<sockaddr*>(&host); if (getsockname(m_socket, hostPtr, &hostSize) == SOCKET_INVALID) { return NULL; } return inet_ntoa(host.sin_addr); }
//----------------------------------------------------------------------- // PANEL DECORATOR //----------------------------------------------------------------------- CAnimatedPanelDecorator::CAnimatedPanelDecorator(QWidget* pDecoratedWidget, QGraphicsScene* pScene, EnumPlacement ePlacement, int iScreenOffset, const QString& openPanelIconFileName, const QString& openPanelText, int iButtonOffset, const QString& openIcon /*= ""*/, const QString& closeIcon /*= ""*/) : m_pOpenPanelButton(0) , m_pDecoratedWidget(pDecoratedWidget) { m_pOpenPanelButton = new QPushButton(); if (!openPanelIconFileName.isEmpty()) m_pOpenPanelButton->setIcon(QIcon(openPanelIconFileName)); m_pOpenPanelButton->setText(openPanelText); m_pPanelAnimator = new PanelAnimator(pScene, pDecoratedWidget, ePlacement, iScreenOffset, m_pOpenPanelButton, true, iButtonOffset, openIcon, closeIcon); connect(m_pPanelAnimator, SIGNAL(opened()), this, SIGNAL(opened())); connect(m_pPanelAnimator, SIGNAL(closed()), this, SIGNAL(closed())); connect(m_pPanelAnimator, SIGNAL(opening()), this, SIGNAL(opening())); connect(m_pPanelAnimator, SIGNAL(closing()), this, SIGNAL(closing())); }
bool Socket::bind(int port) { ASSERT(opened()); sockaddr_in host; host.sin_family = AF_INET; host.sin_addr.s_addr = INADDR_ANY; host.sin_port = htons(static_cast<unsigned short>(port)); const sockaddr* const hostPtr = reinterpret_cast<const sockaddr*>(&host); if (::bind(m_socket, hostPtr, sizeof(host)) == SOCKET_INVALID) { return false; } return true; }
void MainWindow::initConnection() { // Show connecting dialog mConnectingDialog->show(); // Connection QNetworkConfigurationManager manager; const bool canStartIAP = (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces); QNetworkConfiguration cfg = manager.defaultConfiguration(); if (!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) return; mNetworkSession = new QNetworkSession(cfg, this); connect(mNetworkSession, SIGNAL(opened()), this, SLOT(connectOpened())); connect(mNetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(connectError(QNetworkSession::SessionError))); mNetworkSession->open(); }
int FS_putbinaryReal(int chn, double x) { if (opened(chn, 3) == -1) { return -1; } if (write(g_file[chn]->binaryfd, &x, sizeof(x)) != sizeof(x)) { FS_errmsg = strerror(errno); return -1; } return 0; }
void ZipFile::extract(const std::string& path) { TraceL << "Extracting zip to: " << path << endl; if (!opened()) throw std::runtime_error("The archive must be opened for extraction."); if (!goToFirstFile()) throw std::runtime_error("Cannot read the source archive."); while (true) { extractCurrentFile(path, true); if (!goToNextFile()) break; } }
RequestQueue::RequestQueue(AdInterface *parent) : QObject(parent) , m_nam(new QNetworkAccessManager(this)) , m_requestRunning(false) , m_confman(new QNetworkConfigurationManager(this)) , m_nsession(0) , m_onlineCheck(false) , m_networkError(false) { connect(m_nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(adRequestFinished(QNetworkReply*))); m_nsession = new QNetworkSession(m_confman->defaultConfiguration(), this); connect(m_nsession, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(netSessionStateChanged(QNetworkSession::State))); connect(m_nsession, SIGNAL(opened()), this, SLOT(netSessionStateChanged())); }
void jpeg::load(const string & fname) { //Clean up old data if (_data != nullptr) delete[] _data; auto reader = io::read(fname, true); if (!reader.opened() || !reader.ok()) throw exception("cant open file"); load(reader); //close file reader.close(); }
int FS_zone(int dev, int zone) { if (opened(dev, 0) == -1) { return -1; } if (zone <= 0) { FS_errmsg = _("non-positive zone width"); return -1; } g_file[dev]->outColWidth = zone; return 0; }
int FS_width(int dev, int width) { if (opened(dev, 0) == -1) { return -1; } if (width < 0) { FS_errmsg = _("negative width"); return -1; } g_file[dev]->outLineWidth = width; return 0; }
int FS_putbinaryString(int chn, const struct String *s) { if (opened(chn, 3) == -1) { return -1; } if (s->length && write(g_file[chn]->binaryfd, s->character, s->length) != s->length) { FS_errmsg = strerror(errno); return -1; } return 0; }
unsigned __int64 TextFile::size() const { ULARGE_INTEGER large; large.QuadPart = 0; if (opened() == true) { large.LowPart = ::GetFileSize(file_, &large.HighPart); if (large.LowPart == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR) { large.QuadPart = 0; } } return large.QuadPart; }
bool Socket::connected() const { if (!opened()) { return false; } if (!wait(MASK_READ, 0)) { return true; } byte buffer = 0; if (peek(&buffer, sizeof(buffer)) == 0) { return false; } return true; }
str file::read(uint size) { assert(opened()); if (size==0) { fseek(fp, 0, SEEK_END); size=ftell(fp); rewind(fp); } char* buffer=new char[size]; if (buffer==NULL) { fputs("Memory error: No buffer for read", stderr); exit(2); } str s(buffer, buffer+fread(buffer, 1, size, fp)); delete buffer; return s; }
int FS_eof(int chn) { struct FileStream *f; if (opened(chn, 1) == -1) { return -1; } f = g_file[chn]; if (f->inSize == f->inCapacity && refill(chn) == -1) { return 1; } return 0; }
int FS_nextline(int dev) { struct FileStream *f; if (opened(dev, 0) == -1) { return -1; } f = g_file[dev]; if (f->outPos && FS_putChar(dev, '\n') == -1) { return -1; } return 0; }
TCP_Song::TCP_Song(void) { // find out name of this machine QString name = QHostInfo::localHostName(); if (!name.isEmpty()) { qDebug() << name << endl; } // find out IP addresses of this machine QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // add non-localhost addresses for (int i = 0; i < ipAddressesList.size(); ++i) { if (!ipAddressesList.at(i).isLoopback()) qDebug() << ipAddressesList.at(i).toString() << endl; } tcpSocket = new QTcpSocket(this); connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readSongs())); QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { // Get saved network configuration QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); // If the saved network configuration is not currently discovered use the system default QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } networkSession = new QNetworkSession(config, this); connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened())); networkSession->open(); } }
void FSBrowser::refresh() { clearItems(); StopProcessing(); if (_model->requiresAuthentication() && !_model->isAuthenticated()) { _authWidget->setUsernameclearPassword(); _authWidget->show(); } else { _authWidget->hide(); bool compact = false; if (_viewType == ListView) { compact = true; _scrollPaneLayout->setContentsMargins(12, 8, 8, 8); //Position Folders _scrollPaneLayout->setSpacing(0); } else { _scrollPaneLayout->setContentsMargins(12, 12, 12, 12); //Position Files in recent _scrollPaneLayout->setSpacing(8); } int id = 0; foreach (const FSEntry &entry, _model->entries()) { FSEntryWidget *button = new FSEntryWidget(entry, _scrollPane); button->setCompact(compact); _buttonGroup->addButton(button, id++); _scrollPaneLayout->addWidget(button); connect(button, SIGNAL(selected()), this, SLOT(entrySelectedHandler())); connect(button, SIGNAL(opened()), this, SLOT(entryOpenedHandler())); } } }
int EditBoxCollection::doOpenFile(char *pName) { int rc = opened(pName); if(rc < 0) { if (!current()->is_untitled() || current()->get_changed()) select(open()); current()->load(pName); SendKey("kbOpen"); } else select(rc); return 0; }
__int64 TextFile::seek(__int64 offset, int origin) { LARGE_INTEGER large; large.QuadPart = 0; if (opened() == true) { large.QuadPart = offset; large.LowPart = ::SetFilePointer(file_, large.LowPart, &large.HighPart, origin); if (large.LowPart == INVALID_SET_FILE_POINTER && ::GetLastError() != NO_ERROR) { large.QuadPart = INVALID_SET_FILE_POINTER; } } return large.QuadPart; }
int FS_putItem(int dev, const struct String *s) { struct FileStream *f; if (opened(dev, 0) == -1) { return -1; } f = g_file[dev]; if (f->outPos && f->outPos + s->length > f->outLineWidth) { FS_nextline(dev); } return FS_putString(dev, s); }
void RS232VisualizerMain::connectionsGUIserial() { connect(topLevel, SIGNAL(guiOpenSerial()),serialPort,SLOT(open())); connect(topLevel, SIGNAL(guiCloseSerial()),serialPort,SLOT(close())); connect(topLevel, SIGNAL(guiSendSerialData(QString)), serialPort, SLOT(write(QString))); connect(topLevel, SIGNAL(guiSetSerialSettingsPort(QString)),serialPort,SLOT(getPortSettings(QString))); connect(topLevel, SIGNAL(guiSetSerialSettingsBaud(QString)),serialPort,SLOT(getBaudSettings(QString))); connect(topLevel, SIGNAL(guiSetSerialSettingsBit(QString)),serialPort,SLOT(getBitSettings(QString))); connect(topLevel, SIGNAL(guiSetSerialSettingsParity(QString)),serialPort,SLOT(getParitySettings(QString))); connect(topLevel, SIGNAL(guiSetSerialSettingsStopbits(QString)),serialPort,SLOT(getStopbitsSettings(QString))); connect(topLevel, SIGNAL(guiSetSerialSettingsFlowcontrol(QString)),serialPort,SLOT(getFlowcontrolSettings(QString))); connect(topLevel, SIGNAL(guiGetAvailableSerialPorts(bool)),serialPort,SLOT(findAvailablePorts(bool))); connect(serialPort,SIGNAL(sendStatusText(QVariant)),topLevel, SLOT(getStatusText(QVariant))); connect(serialPort,SIGNAL(opened()),topLevel,SLOT(serialPortOpenSlot())); connect(serialPort,SIGNAL(serialDataChanged()),topLevel, SLOT(newSerialDataSlot())); }
bool Connection::open() { if(port->isOpen()) return true; if(!port->open(QIODevice::ReadWrite)) { qDebug() << "Nie można otworzyć portu"; return false; } port->setBaudRate(115200); port->setDataBits(QSerialPort::Data8); port->setParity(QSerialPort::NoParity); port->setStopBits(QSerialPort::OneStop); port->setFlowControl(QSerialPort::NoFlowControl); emit opened(); emit log(tr("Połączono"), 1); return true; }
MainWindow::MainWindow(const QVariantHash &programOptions, QWidget *parent) : QMainWindow(parent), m_programOptions(programOptions) { // Set Internet Access Point QNetworkConfigurationManager manager; const bool canStartIAP = (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces); // Is there default access point, use it QNetworkConfiguration cfg = manager.defaultConfiguration(); if (!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) { QMessageBox::information(0, tr("Map Viewer Demo"), tr( "Available Access Points not found.")); qApp->quit(); return; } bool open_session = true; if (m_programOptions.contains("session")) open_session = m_programOptions["session"].toBool(); else if (m_programOptions.contains("nosession")) open_session = !m_programOptions["nosession"].toBool(); if (open_session) { m_session = new QNetworkSession(cfg, this); connect(m_session, SIGNAL(opened()), this, SLOT(networkSessionOpened())); connect(m_session, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(networkSessionError(QNetworkSession::SessionError))); m_session->open(); } else { qDebug("Bypassing session..."); networkSessionOpened(); } setWindowTitle("MapViewer"); resize(640, 480); }
//---------------------------------------------------------------------- HRESULT open( const char *input_file, const char *user_spath = NULL, ea_t load_address = BADADDR, input_exe_reader_t exe_reader = NULL, input_mem_reader_t mem_reader = NULL) { if ( opened() ) return S_OK; // Not initialized yet? if ( !co_initialized ) { // Initialize COM CoInitialize(NULL); co_initialized = true; } return session->open(input_file, user_spath, load_address, exe_reader, mem_reader); }
void Fl_Tool_Bar::preferred_size(int &w, int &h) const { if(opened()) { int H=0; for(int n=0; n<children(); n++) { Fl_Widget *w = child(n); if(w==m_menu || w==m_menubut || w==m_right) continue; int ww = w->w(); int wh = 0; w->preferred_size(ww, wh); if(wh > H) H = wh; } H += layout_spacing()*2 + box()->dh(); h = H; } else { h = glyph_size(); } }