Exemplo n.º 1
0
bool QNativeSocketEnginePrivate::nativeSetMulticastInterface(const QNetworkInterface &iface)
{
#ifndef QT_NO_IPV6
    if (socketProtocol == QAbstractSocket::IPv6Protocol) {
        uint v = iface.isValid() ? iface.index() : 0;
        return (::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_MULTICAST_IF, (char *) &v, sizeof(v)) != -1);
    }
#endif

    struct in_addr v;
    if (iface.isValid()) {
        QList<QNetworkAddressEntry> entries = iface.addressEntries();
        for (int i = 0; i < entries.count(); ++i) {
            const QNetworkAddressEntry &entry = entries.at(i);
            const QHostAddress &ip = entry.ip();
            if (ip.protocol() == QAbstractSocket::IPv4Protocol) {
                v.s_addr = htonl(ip.toIPv4Address());
                int r = ::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (char *) &v, sizeof(v));
                if (r != -1)
                    return true;
            }
        }
        return false;
    }

    v.s_addr = INADDR_ANY;
    return (::setsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, (char *) &v, sizeof(v)) != -1);
}
Exemplo n.º 2
0
    // Go through all interfaces and add all IPs for interfaces that can
    // broadcast and are not local.
    foreach (QNetworkInterface networkInterface,
             QNetworkInterface::allInterfaces())
    {
        if (!networkInterface.addressEntries().isEmpty()
                && networkInterface.isValid())
        {
            QNetworkInterface::InterfaceFlags interfaceFlags =
                    networkInterface.flags();

            if (interfaceFlags & QNetworkInterface::IsUp
                    && interfaceFlags & QNetworkInterface::IsRunning
                    && interfaceFlags & QNetworkInterface::CanBroadcast
                    && !(interfaceFlags & QNetworkInterface::IsLoopBack))
            {
                qDebug() << "ConnectionManager::handleNetworkSessionOpened():"
                         << "The connection is valid!";

                if (mNetworkSession) {
                    mAccessPoint = mNetworkSession->configuration().name();
                    emit accessPointChanged(mAccessPoint);
                }

                mMyIp.setAddress(networkInterface.addressEntries().at(0).ip().toString());
                emit myIpChanged(mMyIp.toString());

                setState(Connected);
                return;
            }
        }
    }
void SpeedWrapper::gconf_value_changed()
{
    bool ok;
    //check netspeed enabled
    if(!m_gconf_enabled->value().isValid())
        m_gconf_enabled->set(true);
    //check netspeed interface
    if(!m_gconf_speed_interface->value().isValid())
        m_gconf_speed_interface->set("wlan0");
    //check netspeed update time
    if(!m_gconf_update_time->value().isValid())
        m_gconf_update_time->set(1000);
    //check when online
    if(!m_gconf_when_online->value().isValid())
        m_gconf_when_online->set(false);


    m_is_enabled = m_gconf_enabled->value().toBool();
    m_speed_interface = m_gconf_speed_interface->value().toString();
    m_when_online = m_gconf_when_online->value().toBool();

    if(m_speed_interface.isEmpty() || m_speed_interface.isNull())
        m_speed_interface = "wlan0";
    m_update_time = m_gconf_update_time->value().toInt(&ok);
    if(!ok)
        m_update_time = 1000;

    QNetworkInterface interface = QNetworkInterface::interfaceFromName(m_speed_interface);
    m_network_interface_valid = interface.isValid();
    bool online = (interface.flags().testFlag(QNetworkInterface::IsUp) &&
                  interface.flags().testFlag(QNetworkInterface::IsRunning));
    if(online != m_isOnline)
    {
        emit onlineChanged(online);
        updateData();
    }
    m_isOnline = online;

    if(m_is_enabled)
    {
        if(m_when_online)
        {
            if(m_isOnline)
            {
                m_timer->stop();
                m_timer->start(m_update_time);
            }else{
                m_timer->stop();
            }
        }else{
            m_timer->stop();
            m_timer->start(m_update_time);
        }
    }else{
        m_timer->stop();
    }
}
Exemplo n.º 4
0
// ----------------------------------------------------------------------------
// getHostAddress (static)
// ----------------------------------------------------------------------------
QHostAddress NetworkTools::getHostAddress(const QNetworkInterface &in_interface)
{
    if (in_interface.isValid() == false) return QHostAddress();

    QList<QNetworkAddressEntry> addr_entry_list = in_interface.addressEntries();
    if (addr_entry_list.isEmpty()) return QHostAddress();

    return addr_entry_list.first().ip();
}
Exemplo n.º 5
0
        void Inet6AddressHolder::init(QByteArray addr, QNetworkInterface nif)
            throw (UnknownHostException)
        {
            setAddr(addr);

            if (nif.isValid()) {
                this->scope_id = nif.index();//deriveNumericScope(ipaddress, nif);
                this->scope_id_set = true;
                this->scope_ifname = nif;
                this->scope_ifname_set = true;
            }
        }
Exemplo n.º 6
0
void MainWindow::onlineStateChange()
{
    static bool netUp = false;
    bool bState = false;
    QNetworkInterface netInterface = QNetworkInterface::interfaceFromName(NET_NAME);
    //qDebug()<<netInterface;
    if (netInterface.isValid())
    {
        if (netInterface.flags().testFlag(QNetworkInterface::IsUp) && 
            netInterface.flags().testFlag(QNetworkInterface::IsRunning))
        {
            if (!netUp) 
            {
                repaint();
                netUp = true;
            }
            QHostInfo host = QHostInfo::fromName(WEB_SITE);
            if (!host.addresses().isEmpty()) 
            {
                repaint();
                Global::s_netState = true;
                bState = true;
                m_shangChun->UploadData();
            }
            else
            {
                repaint();
                Global::s_netState = false;
                bState = false;
            }
        }
        else
        {
            repaint();
            Global::s_netState = false;
            bState = false;
            netUp = false;
        }
    }

    if(bState)
    {
        QImage NetImage(":/images/NetConn24.ico");
        this->network->setPixmap(QPixmap::fromImage(NetImage));
    }
    else
    {
        QImage NetImage(":/images/NetDisConn24.ico");
        this->network->setPixmap(QPixmap::fromImage(NetImage));
    }

    SetUnUpCount();
}
Exemplo n.º 7
0
void PJobRunnerNetworkScanner::scan(const QNetworkInterface& interface){
    foreach(const QNetworkAddressEntry& address_entry, interface.addressEntries()){
        if(m_want_stop) break;
        quint32 netmask = address_entry.netmask().toIPv4Address();
        quint32 local_ip = address_entry.ip().toIPv4Address();
        quint32 address_to_try = (local_ip & netmask) + 1;
        //quint32 inv_netmask = ~netmask;

        if(interface.humanReadableName() == "lo"){
            std::cout << "Skipping interface \"lo\"." << std::endl;
            continue;
        }

        if(!interface.isValid()){
            std::cout << "Skipping interface \"" << interface.humanReadableName().toStdString() << "\"." << std::endl;
            continue;
        }

        if(address_entry.ip().protocol() != QAbstractSocket::IPv4Protocol){
            std::cout << "Skipping non-IPv4 interface." << std::endl;
            continue;
        }

        if(address_entry.ip() == QHostAddress::LocalHost){
            std::cout << "Skipping loopback interface." << std::endl;
            continue;
        }

        if(address_entry.ip().isNull()){
            continue;
        }

        std::cout << "Probing interface " << interface.humanReadableName().toStdString() << std::endl;
        std::cout << "Local address is " << interface.hardwareAddress().toStdString() << std::endl;
        std::cout << "Netmask: " << address_entry.netmask().toString().toStdString() << std::endl;
        std::cout << "Searching local network..." << std::endl;
        while((address_to_try & netmask) == (local_ip & netmask)){
            if(m_want_stop) break;
            std::cout << "\r" << QHostAddress(address_to_try).toString().toStdString();
            std::cout.flush();
            emit probing_host(QHostAddress(address_to_try));
            PJobRunnerSessionWrapper* session = new PJobRunnerSessionWrapper(QHostAddress(address_to_try), 50);
            if(session->is_valid()) found(session);
            else delete session;
            address_to_try++;
        }
    }
    emit finished_scanning();
    m_want_stop = false;
}
QNetworkInterface QNetworkInfoPrivate::interfaceForMode(QNetworkInfo::NetworkMode mode, int interface)
{
    switch (mode) {
    case QNetworkInfo::WlanMode: {
        QStringList dirs = QDir(*NETWORK_SYSFS_PATH()).entryList(*WLAN_MASK());
        if (interface < dirs.size()) {
            QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(dirs.at(interface));
            if (networkInterface.isValid())
                return networkInterface;
        }
        break;
    }

    case QNetworkInfo::EthernetMode: {
        QStringList dirs = QDir(*NETWORK_SYSFS_PATH()).entryList(*ETHERNET_MASK());
        if (interface < dirs.size()) {
            QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(dirs.at(interface));
            if (networkInterface.isValid())
                return networkInterface;
        }
        break;
    }

//    case QNetworkInfo::BluetoothMode:
//    case QNetworkInfo::GsmMode:
//    case QNetworkInfo::CdmaMode:
//    case QNetworkInfo::WcdmaMode:
//    case QNetworkInfo::WimaxMode:
//    case QNetworkInfo::LteMode:
//    case QNetworkInfo::TdscdmaMode:
    default:
        break;
    };

    return QNetworkInterface();
}
Exemplo n.º 9
0
// ----------------------------------------------------------------------------
// getHostAddress (static)
// ----------------------------------------------------------------------------
QHostAddress NetworkTools::getHostAddress(const QNetworkConfiguration &in_network_config)
{
    if (in_network_config.isValid() == false) return QHostAddress();

    qDebug() << "NetworkTools::getHostAddress - configuration bearer type:" << in_network_config.bearerTypeName();

    QNetworkSession nws(in_network_config);
    if (nws.state() == QNetworkSession::Invalid || nws.state() == QNetworkSession::NotAvailable) return QHostAddress();

    qDebug() << "NetworkTools::getHostAddress - session state:" << nws.state();

    QNetworkInterface nwi = nws.interface();
    if (nwi.isValid() == false) return QHostAddress();
    if (nwi.addressEntries().isEmpty()) return QHostAddress();

    foreach(QNetworkAddressEntry temp, nwi.addressEntries())
        qDebug() << "NetworkTools::getHostAddress - session addr entry:" << temp.ip().toString();

    QNetworkAddressEntry nwae = nwi.addressEntries().first();
    QHostAddress host_address = nwae.ip();

    return host_address;
}
Exemplo n.º 10
0
static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
                                      int how6,
                                      int how4,
                                      const QHostAddress &groupAddress,
                                      const QNetworkInterface &iface)
{
    int level = 0;
    int sockOpt = 0;
    char *sockArg;
    int sockArgSize;

    struct ip_mreq mreq4;
#ifndef QT_NO_IPV6
    struct ipv6_mreq mreq6;

    if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) {
        level = IPPROTO_IPV6;
        sockOpt = how6;
        sockArg = reinterpret_cast<char *>(&mreq6);
        sockArgSize = sizeof(mreq6);
        memset(&mreq6, 0, sizeof(mreq6));
        Q_IPV6ADDR ip6 = groupAddress.toIPv6Address();
        memcpy(&mreq6.ipv6mr_multiaddr, &ip6, sizeof(ip6));
        mreq6.ipv6mr_interface = iface.index();
    } else
#endif
    if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol) {
        level = IPPROTO_IP;
        sockOpt = how4;
        sockArg = reinterpret_cast<char *>(&mreq4);
        sockArgSize = sizeof(mreq4);
        memset(&mreq4, 0, sizeof(mreq4));
        mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());

        if (iface.isValid()) {
            QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
            if (!addressEntries.isEmpty()) {
                QHostAddress firstIP = addressEntries.first().ip();
                mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
            } else {
                d->setError(QAbstractSocket::NetworkError,
                            QNativeSocketEnginePrivate::NetworkUnreachableErrorString);
                return false;
            }
        } else {
            mreq4.imr_interface.s_addr = INADDR_ANY;
        }
    } else {
        // unreachable
        d->setError(QAbstractSocket::UnsupportedSocketOperationError,
                    QNativeSocketEnginePrivate::ProtocolUnsupportedErrorString);
        return false;
    }

    int res = setsockopt(d->socketDescriptor, level, sockOpt, sockArg, sockArgSize);
    if (res == -1) {
        d->setError(QAbstractSocket::UnsupportedSocketOperationError,
                    QNativeSocketEnginePrivate::OperationUnsupportedErrorString);
        return false;
    }
    return true;
}
Exemplo n.º 11
0
void QGenericEngine::doRequestUpdate()
{
#ifndef QT_NO_NETWORKINTERFACE
    QMutexLocker locker(&mutex);

    // Immediately after connecting with a wireless access point
    // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a
    // second time results in a non-empty list. If we loose interfaces we will end up removing
    // network configurations which will break current sessions.
    QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
    if (interfaces.isEmpty())
        interfaces = QNetworkInterface::allInterfaces();

    QStringList previous = accessPointConfigurations.keys();

    // create configuration for each interface
    while (!interfaces.isEmpty()) {
        QNetworkInterface interface = interfaces.takeFirst();

        if (!interface.isValid())
            continue;

        // ignore loopback interface
        if (interface.flags() & QNetworkInterface::IsLoopBack)
            continue;

        // ignore WLAN interface handled in separate engine
        if (qGetInterfaceType(interface.name()) == QNetworkConfiguration::BearerWLAN)
            continue;

        uint identifier;
        if (interface.index())
            identifier = qHash(QLatin1String("generic:") + QString::number(interface.index()));
        else
            identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress());

        const QString id = QString::number(identifier);

        previous.removeAll(id);

        QString name = interface.humanReadableName();
        if (name.isEmpty())
            name = interface.name();

        QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined;
        if((interface.flags() & QNetworkInterface::IsUp) && !interface.addressEntries().isEmpty())
            state |= QNetworkConfiguration::Active;

        if (accessPointConfigurations.contains(id)) {
            QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);

            bool changed = false;

            ptr->mutex.lock();

            if (!ptr->isValid) {
                ptr->isValid = true;
                changed = true;
            }

            if (ptr->name != name) {
                ptr->name = name;
                changed = true;
            }

            if (ptr->id != id) {
                ptr->id = id;
                changed = true;
            }

            if (ptr->state != state) {
                ptr->state = state;
                changed = true;
            }

            ptr->mutex.unlock();

            if (changed) {
                locker.unlock();
                emit configurationChanged(ptr);
                locker.relock();
            }
        } else {
            QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);

            ptr->name = name;
            ptr->isValid = true;
            ptr->id = id;
            ptr->state = state;
            ptr->type = QNetworkConfiguration::InternetAccessPoint;
            ptr->bearerType = qGetInterfaceType(interface.name());

            accessPointConfigurations.insert(id, ptr);
            configurationInterface.insert(id, interface.name());

            locker.unlock();
            emit configurationAdded(ptr);
            locker.relock();
        }
    }

    while (!previous.isEmpty()) {
        QNetworkConfigurationPrivatePointer ptr =
            accessPointConfigurations.take(previous.takeFirst());

        configurationInterface.remove(ptr->id);

        locker.unlock();
        emit configurationRemoved(ptr);
        locker.relock();
    }

    locker.unlock();
#endif

    emit updateCompleted();
}
Exemplo n.º 12
0
static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
                                      int how6,
                                      int how4,
                                      const QHostAddress &groupAddress,
                                      const QNetworkInterface &interface)
{
    int level = 0;
    int sockOpt = 0;
    void *sockArg;
    int sockArgSize;

    ip_mreq mreq4;
    ipv6_mreq mreq6;

    if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) {
        level = IPPROTO_IPV6;
        sockOpt = how6;
        sockArg = &mreq6;
        sockArgSize = sizeof(mreq6);
        memset(&mreq6, 0, sizeof(mreq6));
        Q_IPV6ADDR ip6 = groupAddress.toIPv6Address();
        memcpy(&mreq6.ipv6mr_multiaddr, &ip6, sizeof(ip6));
        mreq6.ipv6mr_interface = interface.index();
    } else
    if (groupAddress.protocol() == QAbstractSocket::IPv4Protocol) {
        level = IPPROTO_IP;
        sockOpt = how4;
        sockArg = &mreq4;
        sockArgSize = sizeof(mreq4);
        memset(&mreq4, 0, sizeof(mreq4));
        mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());

        if (interface.isValid()) {
            QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
            if (!addressEntries.isEmpty()) {
                QHostAddress firstIP = addressEntries.first().ip();
                mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
            } else {
                d->setError(QAbstractSocket::NetworkError,
                            QNativeSocketEnginePrivate::NetworkUnreachableErrorString);
                return false;
            }
        } else {
            mreq4.imr_interface.s_addr = INADDR_ANY;
        }
    } else {
        // unreachable
        d->setError(QAbstractSocket::UnsupportedSocketOperationError,
                    QNativeSocketEnginePrivate::ProtocolUnsupportedErrorString);
        return false;
    }

    int res = setsockopt(d->socketDescriptor, level, sockOpt, sockArg, sockArgSize);
    if (res == -1) {
        switch (errno) {
        case ENOPROTOOPT:
            d->setError(QAbstractSocket::UnsupportedSocketOperationError,
                        QNativeSocketEnginePrivate::OperationUnsupportedErrorString);
            break;
        case EADDRNOTAVAIL:
            d->setError(QAbstractSocket::SocketAddressNotAvailableError,
                        QNativeSocketEnginePrivate::AddressNotAvailableErrorString);
            break;
        default:
            d->setError(QAbstractSocket::UnknownSocketError,
                        QNativeSocketEnginePrivate::UnknownSocketErrorString);
            break;
        }
        return false;
    }
    return true;
}
Exemplo n.º 13
0
void QAndroidBearerEngine::updateConfigurations()
{
#ifndef QT_NO_NETWORKINTERFACE
    if (m_connectivityManager == 0)
        return;

    {
        QMutexLocker locker(&mutex);
        QStringList oldKeys = accessPointConfigurations.keys();

        QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
        if (interfaces.isEmpty())
            interfaces = QNetworkInterface::allInterfaces();

        // Create a configuration for each of the main types (WiFi, Mobile, Bluetooth, WiMax, Ethernet)
        foreach (const AndroidNetworkInfo &netInfo, m_connectivityManager->getAllNetworkInfo()) {

            if (!netInfo.isValid())
                continue;

            const QString name = networkConfType(netInfo);
            if (name.isEmpty())
                continue;

            QNetworkConfiguration::BearerType bearerType = getBearerType(netInfo);

            QString interfaceName;
            QNetworkConfiguration::StateFlag state = QNetworkConfiguration::Defined;
            if (netInfo.isAvailable()) {
                if (netInfo.isConnected()) {
                    // Attempt to map an interface to this configuration
                    while (!interfaces.isEmpty()) {
                        QNetworkInterface interface = interfaces.takeFirst();
                        // ignore loopback interface
                        if (!interface.isValid())
                            continue;

                        if (interface.flags() & QNetworkInterface::IsLoopBack)
                            continue;
                        // There is no way to get the interface from the NetworkInfo, so
                        // look for an active interface...
                        if (interface.flags() & QNetworkInterface::IsRunning
                                && !interface.addressEntries().isEmpty()) {
                            state = QNetworkConfiguration::Active;
                            interfaceName = interface.name();
                            break;
                        }
                    }
                }
            }

            const QString key = QString(QLatin1String("android:%1:%2")).arg(name).arg(interfaceName);
            const QString id = QString::number(qHash(key));
            m_configurationInterface[id] = interfaceName;

            oldKeys.removeAll(id);
            if (accessPointConfigurations.contains(id)) {
                QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
                bool changed = false;
                {
                    const QMutexLocker confLocker(&ptr->mutex);

                    if (!ptr->isValid) {
                        ptr->isValid = true;
                        changed = true;
                    }

                    // Don't reset the bearer type to 'Unknown'
                    if (ptr->bearerType != QNetworkConfiguration::BearerUnknown
                            && ptr->bearerType != bearerType) {
                        ptr->bearerType = bearerType;
                        changed = true;
                    }

                    if (ptr->name != name) {
                        ptr->name = name;
                        changed = true;
                    }

                    if (ptr->id != id) {
                        ptr->id = id;
                        changed = true;
                    }

                    if (ptr->state != state) {
                        ptr->state = state;
                        changed = true;
                    }
                } // Unlock configuration

                if (changed) {
                    locker.unlock();
                    Q_EMIT configurationChanged(ptr);
                    locker.relock();
                }
            } else {
                QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);
                ptr->name = name;
                ptr->isValid = true;
                ptr->id = id;
                ptr->state = state;
                ptr->type = QNetworkConfiguration::InternetAccessPoint;
                ptr->bearerType = bearerType;
                accessPointConfigurations.insert(id, ptr);
                locker.unlock();
                Q_EMIT configurationAdded(ptr);
                locker.relock();
            }
        }

        while (!oldKeys.isEmpty()) {
            QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(oldKeys.takeFirst());
            m_configurationInterface.remove(ptr->id);
            locker.unlock();
            Q_EMIT configurationRemoved(ptr);
            locker.relock();
        }

    } // Unlock engine

#endif // QT_NO_NETWORKINTERFACE

    Q_EMIT updateCompleted();
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

	//qInstallMsgHandler(customMessageHandler);	

#ifdef ARM
    //font
    QFont font;
    font.setPointSize(16);
    a.setFont(font);
#endif

    QTextCodec *codec = QTextCodec::codecForName("UTF-8");  

    QTextCodec::setCodecForLocale(codec);  
    QTextCodec::setCodecForCStrings(codec);  
    QTextCodec::setCodecForTr(codec);

    //create dir for update
    QDir appDir;
    appDir.mkpath(TMP_PATH);
    appDir.mkpath(APK_PATH);
    appDir.mkpath(LOG_PATH);
    appDir.mkpath(ENCYPT_LOG_PATH);

    //test network
    int time = 2;
    while(time)
    {
        QNetworkInterface netInterface = QNetworkInterface::interfaceFromName(NET_NAME);
        if (netInterface.isValid())
        {
            if (netInterface.flags().testFlag(QNetworkInterface::IsUp))
            {
                QHostInfo host = QHostInfo::fromName(WEB_SITE);
                if (!host.addresses().isEmpty()) 
                {
                    Global::s_netState = true;
                    break;
                }
            }
        }
        sleep(5);
        --time;
    }

    //msgBox.hide();

    if (!Global::s_netState)
    {
        QMessageBox::information(NULL, APP_NAME, "没有发现网络连接,无法更新软件数据,系统将离线运行!");
    }

    MainWindow w;
    w.setWindowTitle("Welcome");
    w.show();

    if (Global::s_netState)
    {
        Gengxin gengXin(true);
        gengXin.show();
        gengXin.StartUpSoft();
#if 0
        if (Global::s_needRestart)
        {
            QString exePath = qApp->applicationFilePath();
            QString cmd = "unzip ";
            cmd += UPDATE_FILE_NAME;
            QFile::remove(exePath);
            QProcess::execute(cmd);
#ifdef ARM
            Global::reboot();
#else
            QProcess::startDetached(exePath, QStringList());
#endif
            return 0;
        }
#endif
        gengXin.hide();
        if (gengXin.getUpdateDevState())
            w.OnGengxin(false);
        else
            w.startUsbScan();
    }

    return a.exec();
}
Exemplo n.º 15
0
void QED2KSession::configureSession()
{
    qDebug() << Q_FUNC_INFO;
    Preferences pref;
    const unsigned short old_listenPort = m_session->settings().listen_port;
    const unsigned short new_listenPort = pref.listenPort();
    const int down_limit = pref.getED2KDownloadLimit();
    const int up_limit = pref.getED2KUploadLimit();

    // set common settings before for announce correct nick on server
    libed2k::session_settings s = m_session->settings();
    s.client_name = pref.nick().toUtf8().constData();
    s.m_show_shared_catalogs = pref.isShowSharedDirectories();
    s.m_show_shared_files = pref.isShowSharedFiles();
    s.download_rate_limit = down_limit <= 0 ? -1 : down_limit*1024;
    s.upload_rate_limit = up_limit <= 0 ? -1 : up_limit*1024;
    m_session->set_settings(s);

    if (new_listenPort != old_listenPort)
    {
        qDebug() << "stop listen on " << old_listenPort << " and start on " << new_listenPort;
        // do not use iface name
        const QString iface_name; // = misc::ifaceFromHumanName(pref.getNetworkInterfaceMule());

        if (iface_name.isEmpty())
        {
            m_session->listen_on(new_listenPort);
        }
        else
        {
            // Attempt to listen on provided interface
            const QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name);

            if (!network_iface.isValid())
            {
                qDebug("Invalid network interface: %s", qPrintable(iface_name));
                addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red");
                addConsoleMessage(tr("Trying any other network interface available instead."));
                m_session->listen_on(new_listenPort);
            }
            else
            {
                QString ip;
                qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size());

                foreach (const QNetworkAddressEntry &entry, network_iface.addressEntries())
                {
                    qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name));

                    if (m_session->listen_on(new_listenPort, entry.ip().toString().toAscii().constData()))
                    {
                        ip = entry.ip().toString();
                        break;
                    }
                }

                if (m_session->is_listening())
                {
                    addConsoleMessage(tr("Listening on IP address %1 on network interface %2...").arg(ip).arg(iface_name));
                }
                else
                {
                    qDebug("Failed to listen on any of the IP addresses");
                    addConsoleMessage(tr("Failed to listen on network interface %1").arg(iface_name), "red");
                }
            }
        }
    }