Esempio n. 1
0
int main(int argc, char *argv[])
{
    TDEApplication::disableAutoDcopRegistration();
    TDECmdLineArgs::init( argc, argv, "ktrash",
                        I18N_NOOP( "ktrash" ),
                        I18N_NOOP( "Helper program to handle the TDE trash can\n"
				   "Note: to move files to the trash, do not use ktrash, but \"kfmclient move 'url' trash:/\"" ),
                        TDE_VERSION_STRING );
    TDECmdLineArgs::addCmdLineOptions( options );
    TDEApplication app;

    TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs();
    if ( args->isSet( "empty" ) ) {
        // We use a tdeio job instead of linking to TrashImpl, for a smaller binary
        // (and the possibility of a central service at some point)
        TQByteArray packedArgs;
        TQDataStream stream( packedArgs, IO_WriteOnly );
        stream << (int)1;
        TDEIO::Job* job = TDEIO::special( "trash:/", packedArgs );
        (void)TDEIO::NetAccess::synchronousRun( job, 0 );

        // Update konq windows opened on trash:/
        KDirNotify_stub allDirNotify("*", "KDirNotify*");
        allDirNotify.FilesAdded( "trash:/" ); // yeah, files were removed, but we don't know which ones...
        return 0;
    }

#if 0
    // This is only for testing. KDesktop handles it automatically.
    if ( args->isSet( "migrate" ) ) {
        TQByteArray packedArgs;
        TQDataStream stream( packedArgs, IO_WriteOnly );
        stream << (int)2;
        TDEIO::Job* job = TDEIO::special( "trash:/", packedArgs );
        (void)TDEIO::NetAccess::synchronousRun( job, 0 );
        return 0;
    }
#endif

    TQCString restoreArg = args->getOption( "restore" );
    if ( !restoreArg.isEmpty() ) {

        if (restoreArg.find("system:/trash")==0) {
            restoreArg.remove(0, 13);
            restoreArg.prepend("trash:");
        }

        KURL trashURL( restoreArg );
        if ( !trashURL.isValid() || trashURL.protocol() != "trash" ) {
            kdError() << "Invalid URL for restoring a trashed file:" << trashURL << endl;
            return 1;
        }

        TQByteArray packedArgs;
        TQDataStream stream( packedArgs, IO_WriteOnly );
        stream << (int)3 << trashURL;
        TDEIO::Job* job = TDEIO::special( trashURL, packedArgs );
        bool ok = TDEIO::NetAccess::synchronousRun( job, 0 );
        if ( !ok )
            kdError() << TDEIO::NetAccess::lastErrorString() << endl;
        return 0;
    }

    return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    //KApplication::disableAutoDcopRegistration();
    KCmdLineArgs::init( argc, argv, "ktrash", "kio_trash",
                        ki18n( "ktrash" ),
                        KDE_VERSION_STRING ,
                        ki18n( "Helper program to handle the KDE trash can\n"
				   "Note: to move files to the trash, do not use ktrash, but \"kioclient move 'url' trash:/\"" ));

    KCmdLineOptions options;
    options.add("empty", ki18n( "Empty the contents of the trash" ));
    //{ "migrate", I18N_NOOP( "Migrate contents of old trash" ), 0 },
    options.add("restore <file>", ki18n( "Restore a trashed file to its original location" ));
    // This hack is for the servicemenu on trash.desktop which uses Exec=ktrash -empty. %f is implied...
    options.add("+[ignored]", ki18n( "Ignored" ));
    KCmdLineArgs::addCmdLineOptions( options );
    KApplication app;

    KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
    if ( args->isSet( "empty" ) ) {
        // We use a kio job instead of linking to TrashImpl, for a smaller binary
        // (and the possibility of a central service at some point)
        QByteArray packedArgs;
        QDataStream stream( &packedArgs, QIODevice::WriteOnly );
        stream << (int)1;
        KIO::Job* job = KIO::special( KUrl("trash:/"), packedArgs );
        (void)KIO::NetAccess::synchronousRun( job, 0 );

        // Update konq windows opened on trash:/
        org::kde::KDirNotify::emitFilesAdded(QString::fromLatin1("trash:/")); // yeah, files were removed, but we don't know which ones...
        return 0;
    }

#if 0
    // This is only for testing. KDesktop handles it automatically.
    if ( args->isSet( "migrate" ) ) {
        QByteArray packedArgs;
        QDataStream stream( packedArgs, QIODevice::WriteOnly );
        stream << (int)2;
        KIO::Job* job = KIO::special( "trash:/", packedArgs );
        (void)KIO::NetAccess::synchronousRun( job, 0 );
        return 0;
    }
#endif

    QString restoreArg = args->getOption( "restore" );
    if ( !restoreArg.isEmpty() ) {

        if (restoreArg.indexOf(QLatin1String("system:/trash"))==0) {
            restoreArg.remove(0, 13);
            restoreArg.prepend(QString::fromLatin1("trash:"));
        }

        KUrl trashURL( restoreArg );
        if ( !trashURL.isValid() || trashURL.protocol() != QLatin1String("trash") ) {
            kError() << "Invalid URL for restoring a trashed file:" << trashURL << endl;
            return 1;
        }

        QByteArray packedArgs;
        QDataStream stream( &packedArgs, QIODevice::WriteOnly );
        stream << (int)3 << trashURL;
        KIO::Job* job = KIO::special( trashURL, packedArgs );
        bool ok = KIO::NetAccess::synchronousRun( job, 0 );
        if ( !ok )
            kError() << KIO::NetAccess::lastErrorString() << endl;
        return 0;
    }

    return 0;
}