Пример #1
0
bool KFileShare::setShared(const QString &path, bool shared)
{
    if(!KFileShare::sharingEnabled() || KFileShare::shareMode() == Advanced)
        return false;

    kdDebug(7000) << "KFileShare::setShared " << path << "," << shared << endl;
    QString exe = KFileShare::findExe("fileshareset");
    if(exe.isEmpty())
        return false;

    KProcess proc;
    proc << exe;
    if(shared)
        proc << "--add";
    else
        proc << "--remove";
    proc << path;
    proc.start(KProcess::Block); // should be ok, the perl script terminates fast
    bool ok = proc.normalExit() && (proc.exitStatus() == 0);
    kdDebug(7000) << "KFileSharePropsPlugin::setShared normalExit=" << proc.normalExit() << endl;
    kdDebug(7000) << "KFileSharePropsPlugin::setShared exitStatus=" << proc.exitStatus() << endl;
    if(proc.normalExit())
    {
        switch(proc.exitStatus())
        {
            case 1:
                // User is not authorized
                break;
            case 3:
                // Called script with --add, but path was already shared before.
                // Result is nevertheless what the client wanted, so
                // this is alright.
                ok = true;
                break;
            case 4:
                // Invalid mount point
                break;
            case 5:
                // Called script with --remove, but path was not shared before.
                // Result is nevertheless what the client wanted, so
                // this is alright.
                ok = true;
                break;
            case 6:
                // There is no export method
                break;
            case 7:
                // file sharing is disabled
                break;
            case 8:
                // advanced sharing is enabled
                break;
            case 255:
                // Abitrary error
                break;
        }
    }

    return ok;
}
Пример #2
0
// if it's e.g. just 'www', try if it's a hostname in the local search domain
bool LocalDomainURIFilter::isLocalDomainHost( QString& cmd ) const
{
    // find() returns -1 when no match -> left()/truncate() are noops then
    QString host( cmd.left( cmd.find( '/' ) ) );
    host.truncate( host.find( ':' ) ); // Remove port number

    if( !(host == last_host && last_time > time( NULL ) - 5 ) ) {

        QString helper = KStandardDirs::findExe(QString::fromLatin1( "klocaldomainurifilterhelper" ));
        if( helper.isEmpty())
            return last_result = false;

        m_fullname = QString::null;

        KProcess proc;
        proc << helper << host;
        connect( &proc, SIGNAL(receivedStdout(KProcess *, char *, int)),
                 SLOT(receiveOutput(KProcess *, char *, int)) );
        if( !proc.start( KProcess::NotifyOnExit, KProcess::Stdout ))
            return last_result = false;

        last_host = host;
        last_time = time( (time_t *)0 );

        last_result = proc.wait( 1 ) && proc.normalExit() && !proc.exitStatus();

        if( !m_fullname.isEmpty() )
            cmd.replace( 0, host.length(), m_fullname );
    }
Пример #3
0
void DeviceSettings::startDhcpcd() {
    KProcess startdhcpcd;
    startdhcpcd << "/sbin/dhcpcd" << _dev;
    startdhcpcd.start();
    startdhcpcd.wait();

    if ( !startdhcpcd.normalExit() )
        printf( "failed (start)\n" );
}
Пример #4
0
bool ValgrindDialog::isNewValgrindVersion( ) const
{
  KProcess *proc = new KProcess;
  proc->setUseShell(true);
  *proc << "test \"valgrind-20\" == `valgrind --version | awk -F \\. '{print $1$2}'`";
  proc->start(KProcess::Block);
  if (proc->normalExit())
    return proc->exitStatus();
  return true;
}
Пример #5
0
bool KGVDocument::convertFromPDF( const QString& saveFileName, 
                                    unsigned int firstPage,
                                    unsigned int lastPage )
{
    // TODO -- timeout/fail on this conversion (it can hang on a bad pdf)
    // TODO -- use output from gs (leave out -q) to drive a progress bar
    KProcess process;
    process << _interpreterPath
            << "-q"
            << "-dNOPAUSE"
            << "-dBATCH"
            << "-dSAFER"
            << "-dPARANOIDSAFER"
            << "-sDEVICE=pswrite"
            << ( QCString("-sOutputFile=")+QFile::encodeName(saveFileName) )
            << ( QString("-dFirstPage=")+QString::number( firstPage ) )
            << ( QString("-dLastPage=")+QString::number( lastPage ) )
            << "-c"
            << "save"
            << "pop"
            << "-f"
            << QFile::encodeName(_fileName);

    /*QValueList<QCString> args = process.args();
    QValueList<QCString>::Iterator it = args.begin();
    for ( ; it != args.end() ; ++it )
        kdDebug(4500) << ( *it ) << endl;*/

    if( !process.start( KProcess::Block ) )
    {
	kdError() << "convertFromPDF: Couldn't start gs process" << endl;
	// TODO -- error message (gs not found?)
	return false;
    }
    if ( !process.normalExit() || process.exitStatus() != 0 )
    {
	kdError() << "convertFromPDF: normalExit=" << process.normalExit() << " exitStatus=" << process.exitStatus() << endl;
	// TODO -- error message (can't open, strerr())
	return false;
    }

    return true;
}
void SqlBackendTest::allTests()
{
	QString dbname = "test";

	Classes::setup();

	// Drop the database if already exists
	KProcess *proc = new KProcess;
	*proc << "dropdb";
	*proc << dbname;
	proc->start();
	proc->wait();
	delete proc;

	// Create the database
	proc = new KProcess;
	*proc << "createdb";
	*proc << dbname;
	CHECK( proc->start(), true );
	proc->wait();
	if ( ! proc->normalExit() || proc->exitStatus() != 0 ) {
		CHECK( true, false );
		delete proc;
		return;
	}
	delete proc;

	QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" );
	db->setDatabaseName( dbname );
	db->setUserName( "albert" );
	db->setPassword( "" );
	db->setHostName( "localhost" );
	if ( ! db->open() ) {
		kdDebug() << "Failed to open database: " << db->lastError().text() << endl;
		return;
	}
	DbBackendIface *backend = new SqlDbBackend( db );

	m_manager = new Manager( backend );
	m_manager->createSchema();

	transactions();
	collections();
	cache();
	freeing();
	testRelations();

	delete m_manager;
}
void MultipleBackendsTest::xml2sql()
{
	QString dbname = "testmultiple";
	// Drop the database if already exists
	KProcess *proc = new KProcess;
	*proc << "dropdb";
	*proc << dbname;
	proc->start();
	proc->wait();
	delete proc;

	// Create the database
	proc = new KProcess;
	*proc << "createdb";
	*proc << dbname;
	CHECK( proc->start(), true );
	proc->wait();
	if ( ! proc->normalExit() || proc->exitStatus() != 0 ) {
		CHECK( true, false );
		delete proc;
		return;
	}
	delete proc;

	DbBackendIface *backend1 = new XmlDbBackend( "database.xml" );
	Manager *manager1 = new Manager( backend1 );
	manager1->createSchema();

	QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" );
	db->setDatabaseName( dbname );
	db->setUserName( "ak213" );
	db->setPassword( "ak" );
	db->setHostName( "localhost" );
	if ( ! db->open() ) {
		kdDebug() << "Failed to open database: " << db->lastError().text() << endl;
		return;
	}
	DbBackendIface *backend2 = new SqlDbBackend( db );
	Manager *manager2 = new Manager( backend2 );
	manager2->createSchema();
	manager1->copyTo( manager2 );
	manager2->commit();
	delete manager2;
	delete manager1;
	QSqlDatabase::removeDatabase( db );
}
void DynamicObjectsTest::allTests()
{
	QString dbname = "testdynamic";
	
	Classes::setup();

	Classes::addClass( "Test", DynamicObject::createInstance, 0 );
	ClassInfo *ci = Classes::classInfo( "Test" );
	ci->addObject( "Customer", "Customer_Test", &Customer::createInstance );
	ci->addCollection( "Article", "Article_Test" );

	PropertyInfo *p;
	
	p = new PropertyInfo();
	p->setName( "Property1" );
	p->setType( QVariant::String );
	ci->addProperty( p );
	
	p = new PropertyInfo();
	p->setName( "Property2" );
	p->setType( QVariant::ULongLong );
	ci->addProperty( p );

	Classes::setupRelations();

	// Drop the database if already exists
	KProcess *proc = new KProcess;
	*proc << "dropdb";
	*proc << dbname;
	proc->start();
	proc->wait();
	delete proc;

	// Create the database
	proc = new KProcess;
	*proc << "createdb";
	*proc << dbname;
	CHECK( proc->start(), true );
	proc->wait();
	if ( ! proc->normalExit() || proc->exitStatus() != 0 ) {
		CHECK( true, false );
		delete proc;
		return;
	}
	delete proc;

	QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" );
	db->setDatabaseName( dbname );
	db->setUserName( "ak213" );
	db->setPassword( "ak" );
	db->setHostName( "localhost" );
	if ( ! db->open() ) {
		kdDebug() << "Failed to open database: " << db->lastError().text() << endl;
		return;
	}
	DbBackendIface *backend = new SqlDbBackend( db );

	m_manager = new Manager( backend );
	m_manager->setMaxObjects( 1 );
	m_manager->createSchema();


	ObjectRef<Customer> customer = Customer::create();
	customer->setCustomerName( "Name of the customer" );

	ObjectRef<Article> a1 = Article::create();
	a1->setCode( "00001" );
	ObjectRef<Article> a2 = Article::create();
	a2->setCode( "00002" );

	ObjectRef<Object> obj = Classes::classInfo( "Test" )->create();
	CHECK( obj->property( "Property1" ).type(), QVariant::String );
	CHECK( obj->property( "Property2" ).type(), QVariant::ULongLong );
	CHECK( obj->containsObject( "Customer_Test" ), true );
	CHECK( obj->containsCollection( "Article_Test" ), true );
	obj->setProperty( "Property1", "Property number one" );
	obj->setProperty( "Property2", 2 );
	CHECK( obj->property( QString( "Property1" ) ).value().toString(), QString( "Property number one" ) );
	CHECK( obj->property( QString( "Property2" ) ).value().toULongLong(), 2 );
	
	obj->setObject( "Customer_Test", customer );
	obj->collection( "Article_Test" )->add( a1 );
	obj->collection( "Article_Test" )->add( a2 );

	m_manager->commit();

	CHECK( obj->property( "Property1" ).value().toString(), QString( "Property number one" ) );

	delete m_manager;
}
Пример #9
0
void DeviceSettings::slotApply()
{
    bool succeed = true;

    /* Manual Settings */
    if ( manualButton->isChecked() ) {
        // SET IP
        int ret = set_iface( _dev.ascii(),
                             ipaddr->text().ascii(),
                             // we can ommit broadcast and netmask.
                             broadcast->text().length() ? broadcast->text().ascii() : 0,
                             netmask->text().length() ? netmask->text().ascii() : 0
            );
        if ( ret < 0 ) succeed = false;

        // SET ROUTE
        if ( !defaultgw->text().isEmpty() ) {
            ret =  set_default_route( defaultgw->text().ascii() );
            if ( ret < 0 ) succeed = false;
        }

        ret = writeDnsList();
        if ( ret < 0 ) succeed = false;

    }
    /* Automatic (DHCP) */
    else if ( automaticButton->isChecked() ) {
        // I don't like to invoke programs directly
        // but we have no chance for now,
        // this is clearly a bad hack :(.

        QFile pidfile( "/var/run/dhcpcd-" + _dev + ".pid" );
        if ( pidfile.exists() ) {
            KProcess killdhcpcd;
            killdhcpcd << "/sbin/dhcpcd" << "-k" << _dev;
            killdhcpcd.start();
            killdhcpcd.wait();

            // how ugly... wait 2 seconds to dhcpcd to finish its work...
            if ( killdhcpcd.normalExit() )
                QTimer::singleShot( 2000, this, SLOT( startDhcpcd() ) );
            else
                printf( "failed (kill)\n" );
        }
        else
            startDhcpcd();
    }

    writeSettings();

    if ( succeed ) {
        QString msg = i18n( "Successfully configured device: " ) + _dev;
        KMessageBox::information( this, msg, i18n( "Done!" ) );
    }
    else {
        QString msg = i18n( "Failed to configure device: " ) + _dev;
        KMessageBox::error( this, msg, i18n( "Error!" ) );
    }

    done( 0 );
}