Exemple #1
0
  BugzillaNoteAddin::BugzillaNoteAddin()
    : gnote::NoteAddin()
  {
    const bool is_first_run
                 = !sharp::directory_exists(images_dir());
    const std::string old_images_dir
      = Glib::build_filename(gnote::Gnote::old_note_dir(),
                             "BugzillaIcons");
    const bool migration_needed
                 = is_first_run
                   && sharp::directory_exists(old_images_dir);

    if (is_first_run)
      g_mkdir_with_parents(images_dir().c_str(), S_IRWXU);

    if (migration_needed)
      migrate_images(old_images_dir);
  }
Exemple #2
0
void KImGalleryPlugin::deleteCancelledGallery(const KURL& url, const QString& sourceDirName, int recursionLevel, const QString& imageFormat)
{
    if (m_recurseSubDirectories && (recursionLevel >= 0)) {
        QStringList subDirList;
        QDir toplevel_dir = QDir( sourceDirName );
        toplevel_dir.setFilter( QDir::Dirs );
        subDirList = toplevel_dir.entryList();

        for (QStringList::ConstIterator it = subDirList.begin(); it != subDirList.end(); it++) {
            if (*it == "." || *it == ".." || *it == "thumbs" || (m_copyFiles && *it == "images")) {
                continue; //disregard the "." and ".." directories
            }
            deleteCancelledGallery( KURL( url.directory() + "/" + *it + "/" + url.fileName() ),
                                    sourceDirName + "/" + *it,
                                    recursionLevel > 1 ? recursionLevel - 1 : 0, imageFormat);
        }
    }

    const QString imgGalleryDir = url.directory();
    QDir thumb_dir( imgGalleryDir + QString::fromLatin1("/thumbs/"));
    QDir images_dir( imgGalleryDir + QString::fromLatin1("/images/"));
    QDir imageDir( sourceDirName, "*.png *.PNG *.gif *.GIF *.jpg *.JPG *.jpeg *.JPEG *.bmp *.BMP",
                   QDir::Name|QDir::IgnoreCase, QDir::Files|QDir::Readable);
    QFile file( url.path() );

    // Remove the image file ..
    file.remove();
    // ..all the thumbnails ..
    for (uint i=0; i < imageDir.count(); i++) {
        const QString imgName = imageDir[i];
        const QString imgNameFormat = imgName + extension(imageFormat);
        bool isRemoved = thumb_dir.remove(imgNameFormat);
        kdDebug(90170) << "removing: " << thumb_dir.path() << "/" << imgNameFormat << "; "<< isRemoved << endl;
    }
    // ..and the thumb directory
    thumb_dir.rmdir(thumb_dir.path());

    // ..and the images directory if images were to be copied
    if (m_copyFiles) {
        for (uint i=0; i < imageDir.count(); i++) {
            const QString imgName = imageDir[i];
            bool isRemoved = images_dir.remove(imgName);
            kdDebug(90170) << "removing: " << images_dir.path() << "/" << imgName << "; "<< isRemoved << endl;
        }
        images_dir.rmdir(images_dir.path());
    }
}
Exemple #3
0
void pre_lzw_mp::do_lzw(QString n){
    QString job = n;
    QString images_src = src + "\\" +n;
    QString write_dst = dst + "\\" + n;
    QString image_name, saved_name;
    int dot_pos;
    QString image_path;
    QDir images_dir(images_src);
    QDir write_dir(dst);
    write_dir.mkdir(job);
    qDebug()<<images_src;
    qDebug()<<write_dst;
    QFileInfoList images_info_list = images_dir.entryInfoList();
    QList<QFileInfo>::iterator image_iter = images_info_list.begin();
    FreeImage_Initialise(true);
    for(; image_iter < images_info_list.end(); ++image_iter){
        if((*image_iter).isDir()){
//            qDebug()<<(*image_iter).fileName();
            continue;
        }
        image_name = (*image_iter).fileName();
        dot_pos = image_name.indexOf(".");
        saved_name = write_dst + "\\" + image_name.left(dot_pos) + "_c.tif";
        image_path = (*image_iter).absoluteFilePath();
        FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(image_path.toStdString().c_str(), 0);
        if(fif == FIF_UNKNOWN){
            fif = FreeImage_GetFIFFromFilename(image_path.toStdString().c_str());
        }
        if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)){
            FIBITMAP *image = FreeImage_Load(fif, image_path.toStdString().c_str());
            FreeImage_Save(FIF_TIFF, image, saved_name.toStdString().c_str(), TIFF_LZW);
            FreeImage_Unload(image);
        }        
    }
    FreeImage_DeInitialise();
}
Exemple #4
0
bool KImGalleryPlugin::createHtml(const KURL& url, const QString& sourceDirName, int recursionLevel, const QString& imageFormat)
{
    if(m_cancelled) return false;


    if( !parent() || !parent()->inherits("KonqDirPart"))
        return false;
    KonqDirPart * part = static_cast<KonqDirPart *>(parent());

    QStringList subDirList;
    if (m_recurseSubDirectories && (recursionLevel >= 0)) { //recursionLevel == 0 means endless
        QDir toplevel_dir = QDir( sourceDirName );
        toplevel_dir.setFilter( QDir::Dirs | QDir::Readable | QDir::Writable );
        subDirList = toplevel_dir.entryList();

        for (QStringList::ConstIterator it = subDirList.begin(); it != subDirList.end() && !m_cancelled; it++) {
            const QString currentDir = *it;
            if (currentDir == "." || currentDir == "..") { continue;} //disregard the "." and ".." directories
            QDir subDir = QDir( url.directory() + "/" + currentDir );
            if (!subDir.exists()) {
                subDir.setPath( url.directory() );
                if (!(subDir.mkdir(currentDir, false))) {
                    KMessageBox::sorry(part->widget(), i18n("Couldn't create folder: %1").arg(subDir.path()));
                    continue;
                } else {
                    subDir.setPath( url.directory() + "/" + currentDir );
                }
            }
            if(!createHtml( KURL( subDir.path() + "/" + url.fileName() ), sourceDirName + "/" + currentDir,
                            recursionLevel > 1 ? recursionLevel - 1 : 0, imageFormat)) { return false; }
        }
    }

    if (m_useCommentFile) {
        loadCommentFile();
    }

    kdDebug(90170) << "sourceDirName: " << sourceDirName << endl;
    //We're interested in only the patterns, so look for the first |
    //#### perhaps an accessor should be added to KImageIO instead?
    QString filter = KImageIO::pattern(KImageIO::Reading).section('|', 0, 0);

    QDir imageDir( sourceDirName, filter.latin1(),
                   QDir::Name|QDir::IgnoreCase, QDir::Files|QDir::Readable);

    const QString imgGalleryDir = url.directory();
    kdDebug(90170) << "imgGalleryDir: " << imgGalleryDir << endl;

    // Create the "thumbs" subdirectory if necessary
    QDir thumb_dir( imgGalleryDir + QString::fromLatin1("/thumbs/"));
    if (createDirectory(thumb_dir, imgGalleryDir, "thumbs") == false)
        return false;

    // Create the "images" subdirectory if necessary
    QDir images_dir( imgGalleryDir + QString::fromLatin1("/images/"));
    if (m_copyFiles) {
        if (createDirectory(images_dir, imgGalleryDir, "images") == false)
            return false;
    }

    QFile file( url.path() );
    kdDebug(90170) << "url.path(): " << url.path() << ", thumb_dir: "<< thumb_dir.path()
              << ", imageDir: "<< imageDir.path() << endl;

    if ( imageDir.exists() && file.open(IO_WriteOnly) ) {
        QTextStream stream(&file);
        stream.setEncoding(QTextStream::Locale);

        createHead(stream);
        createBody(stream, sourceDirName, subDirList, imageDir, url, imageFormat); //ugly

        file.close();

        return !m_cancelled;

    } else {
        KMessageBox::sorry(m_part->widget(),i18n("Couldn't open file: %1").arg(url.path(+1)));
        return false;
    }
}