FileSystemRemoteDialog::FileSystemRemoteDialog(bool isfolder, QWidget *parent) :
    QDialog(parent)
{
    setIsFolder(isfolder);

    labelPath = new QLabel(this);

    pbBack = new QPushButton(tr("Back"), this);
    connect(pbBack, SIGNAL(clicked(bool)), this, SLOT(sltClickedBack(bool)));
    pbBack->setEnabled(false);
    pbBack->setMaximumWidth(40);

    QLabel * l_hLayout = new QLabel("", this);
    l_hLayout->setMinimumHeight(50);
    l_hLayout->setMaximumHeight(60);
    QHBoxLayout *hLayout = new QHBoxLayout(this);
    hLayout->addWidget(labelPath, Qt::AlignLeft);
    hLayout->addWidget(pbBack, Qt::AlignRight);
    l_hLayout->setLayout(hLayout);

    table = new QTableView(this);
    table->setEditTriggers(QAbstractItemView::DoubleClicked);
    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    if(isFolder())
        table->setSelectionMode(QAbstractItemView::SingleSelection);
    else
        table->setSelectionMode(QAbstractItemView::MultiSelection);
    table->setShowGrid(false);
    table->setWordWrap(false);
    connect(table, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(stlDoubleClicked(const QModelIndex&)));

    model = new FileSystemRemote(isFolder(), this);
    table->setModel(model);
    table->setColumnWidth(FileSystemRemote::FIELD_FILENAME, 150);
    table->setColumnWidth(FileSystemRemote::FIELD_TYPE, 70);

    dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Cancel, this);
    connect(dialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(dialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()));

    QVBoxLayout * l = new QVBoxLayout(this);
    l->addWidget(l_hLayout, Qt::AlignJustify);
    l->addWidget(table);
    l->addWidget(dialogButtonBox);
    l->setSpacing(5);
    setLayout(l);

    fsrController = new FileSystemRemoteController(parent);

    if(!isFolder())
        setWindowTitle("Open files...");
    else
        setWindowTitle("Open folder...");

    setModal(true);

    installEventFilter(this);

    m_bWaitResponse = true;
}
void updateInformationsFiles(std::string path){

	DIR* directory = opendir(path.c_str());

    if( directory != NULL ){
        
	    struct dirent* redfile = NULL;

        while( (redfile = readdir( directory )) != NULL ){

	        std::string tmp( redfile->d_name );

	        if( isFolder(path + "/" + tmp) ){
	            
	            if (tmp[0] != '.'){

	            	createInformationFile(path + "/" + tmp, "@server");
	            	updateInformationsFiles(path + "/" + tmp);
	            }
	        }
	        else{

	        	createInformationFile(path + "/" + tmp, "@server");
	        }
	    }
    }
}
Beispiel #3
0
void StFolder::addItem(const StArrayList<StString>& theExtensions,
                       int theDeep,
                       const StString& theSearchFolderPath,
                       const StString& theCurrentItemName) {
    if(theCurrentItemName == IGNORE_DIR_CURR_NAME || theCurrentItemName == IGNORE_DIR_UP_NAME) {
        return;
    }

    StString aCurrItemFullName = theSearchFolderPath + SYS_FS_SPLITTER + theCurrentItemName;
    if(isFolder(aCurrItemFullName)) {
        if(theDeep > 1) {
            StFolder* aSubFolder = new StFolder(theCurrentItemName, this);
            aSubFolder->init(theExtensions, theDeep - 1);
            if(aSubFolder->size() > 0) {
                add(aSubFolder);
            } else {
                // ignore empty folders
                delete aSubFolder;
            }
        }
    } else {
        StString anItemExtension = StFileNode::getExtension(theCurrentItemName);
        for(size_t anExt = 0; anExt < theExtensions.size(); ++anExt) {
            if(anItemExtension.isEqualsIgnoreCase(theExtensions[anExt])) {
                add(new StFileNode(theCurrentItemName, this));
                break;
            }
        }
    }
}
QList<int> QFPseudoTreeModel::folderContentsRows(const QModelIndex &folder) const
{
    if (isFolder(folder)) {
        return folderContentsRows(folderIndexForIndex(folder));
    }
    return QList<int>();
}
TUint32 CMTPDeviceDataProvider::AddEntryL( const TDesC& aPath, TUint32 aParentHandle, TUint32 aStorageId, CMTPObjectMetaData& aObjectInfo  )
    {
    OstTraceFunctionEntry0( CMTPDEVICEDATAPROVIDER_ADDENTRYL_ENTRY );
    
    TBool isFolder( EFalse );
    BaflUtils::IsFolder( Framework().Fs(), aPath, isFolder );
    
    __ASSERT_ALWAYS( isFolder, User::Leave( KErrArgument ));
    __ASSERT_ALWAYS( aParentHandle != KMTPHandleNone, User::Leave( KErrArgument ));
    __ASSERT_ALWAYS( Framework().StorageMgr().ValidStorageId( aStorageId ), User::Leave( KErrArgument ));

    OstTraceExt1(TRACE_NORMAL, CMTPDEVICEDATAPROVIDER_ADDENTRYL, "Add Entry for Path:%S", aPath);
    aObjectInfo.SetUint( CMTPObjectMetaData::EDataProviderId, Framework().DataProviderId() );
    aObjectInfo.SetUint( CMTPObjectMetaData::EFormatCode, EMTPFormatCodeAssociation );
    aObjectInfo.SetUint( CMTPObjectMetaData::EStorageId, aStorageId );
    aObjectInfo.SetDesCL( CMTPObjectMetaData::ESuid, aPath );
    aObjectInfo.SetUint( CMTPObjectMetaData::EFormatSubCode, EMTPAssociationTypeGenericFolder );
    aObjectInfo.SetUint( CMTPObjectMetaData::EParentHandle, aParentHandle );
    aObjectInfo.SetUint( CMTPObjectMetaData::ENonConsumable, EMTPConsumable );
    
    //For example 
    //C:\\Documents\\Sample\\Sample1\\
    //Then "Sample1" is inserted into folderObjects
    TUint length = aPath.Length()-1;//remove '\'
    TPtrC tailFolder( aPath.Ptr(), length );
    TInt pos = tailFolder.LocateReverse( KPathDelimiter ) + 1;
    tailFolder.Set( tailFolder.Right(length - pos));

    aObjectInfo.SetDesCL( CMTPObjectMetaData::EName, tailFolder );
    
    Framework().ObjectMgr().InsertObjectL( aObjectInfo );
    OstTraceFunctionExit0( CMTPDEVICEDATAPROVIDER_ADDENTRYL_EXIT );
    return aObjectInfo.Uint( CMTPObjectMetaData::EHandle );
    }
Beispiel #6
0
void SxPlaylist::reLoad() {
    Logger::printOut("reload play");
    if (m_isValid && !isFolder()) {
        m_thumb = NULL;
        //TODO fix a thumb, why is it never returning any images?
        byte image[20];
        if (sp_playlist_get_image(m_spPlaylist, image)) {
            m_thumb = ThumbStore::getInstance()->getThumb(image);
        }
        Logger::printOut("reload play 3");

        vector<SxTrack*> newTracks;
        for (int index = 0; index < sp_playlist_num_tracks(m_spPlaylist); index++) {
            sp_track* spTrack = sp_playlist_track(m_spPlaylist, index);
            if (!sp_track_get_availability(Session::getInstance()->getSpSession(), spTrack)) continue;
            SxTrack* track = TrackStore::getInstance()->getTrack(spTrack);
            if (track) {
                newTracks.push_back(track);
                //no thumb, lets pick one from the track list
                if (m_thumb == NULL)
                    if (track->getThumb() != NULL)
                        //no need to add ref to the thumb, when the track disappears the playlist will switch thumb
                        m_thumb = track->getThumb();
            }
        }

        removeAllTracks();

        Logger::printOut("reload play done");
        m_tracks = newTracks;
    }
    Utils::updatePlaylist(m_index);
}
Beispiel #7
0
bool Unzip::extractAllFilesTo(const std::string & path, const bool & overwriteExistingFile)
{
	std::string dest_path = path;
	bool extraction_ok = true;

	if(! isFolder(dest_path)){
		dest_path += "/";
	}

	int current = 1;
	std::unordered_map<std::string, std::shared_ptr<InnerZipFileInfo> >::const_iterator iter;
	for(iter = fileInfos.cbegin(); iter != fileInfos.cend(); ++iter){
		const std::string & fileName = iter->first;

		if(isFile(fileName)){
			bool ok = extractFileTo_Internal(fileName,
					                         dest_path + fileName,
					                         fileInfos.size(), current++,
					                         overwriteExistingFile);
			if(!ok){
				extraction_ok = false;
			}
		} else {
			if(createFolderIfNotExists(dest_path + fileName) == false){
				extraction_ok = false;
			}
		}
	}

	return extraction_ok;
}
Beispiel #8
0
void ModelItem::shuffle() {
    if (isFolder()) {
        Rand::shuffle(childItemsList());

        foreach(ModelItem * item, *childItemsList())
            item -> shuffle();
    }
}
Beispiel #9
0
SxPlaylist::~SxPlaylist() {
    sp_playlist_remove_callbacks(m_spPlaylist, &m_plCallbacks, this);
    if (!isFolder()) {
        removeAllTracks();
    }
    //let it bleed a little, not sure if the reference actualy goes up or if it is linked to the container
    // if (m_isValid)
    //   sp_playlist_release(m_spPlaylist);
}
Beispiel #10
0
void ModelItem::accumulateUids(QHash<ModelItem*, QString> & store) {
    if (isFolder()) {
        foreach(ModelItem * item, *childItemsList())
            item -> accumulateUids(store);
    } else {
        QString currUid = toUID();
        if (!currUid.isEmpty()) {
            store.insert(this, currUid);
        }
    }
}
Beispiel #11
0
void TupItemManager::mouseDoubleClickEvent(QMouseEvent *event)
{
    if (event->buttons() == Qt::LeftButton) {
        QTreeWidgetItem *item = currentItem();
        if (item) {
            if (isFolder(item)) 
                emit itemRenamed(item);    
            else
                emit itemRequired();
        }
    }
}
Beispiel #12
0
void FindFiles::findAll(files* f, matcher& m,  bool includeSubFolders, bool skipSystemFolders)
{

    while (FindItem(includeSubFolders, skipSystemFolders))
	{
		fileData fd(AllInfo(), CurrentFolder());
		if (!isFolder() && m.matched(fd))
		{
            f->add(fd);
		}
	}
} // void FindFiles::findAll(files* f)
QVariant QFPseudoTreeModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (isFolder(index)) {
        if (role==Qt::DecorationRole) {
            return QIcon(":/lib/projecttree_folder.png");
        } else if (role==Qt::DisplayRole) {
            int idx=folderIndexForIndex(index);
            if (idx>=0 && idx<m_folders.size()) return m_folders.value(idx);
        }
        return QVariant();
    }

    if (index.internalPointer()) {
        QFPseudoTreeModelItem *item = static_cast<QFPseudoTreeModelItem*>(index.internalPointer());

        if (!item) return QVariant();

        if (role==Qt::DisplayRole) return  item->displayText();
        if (role==Qt::DecorationRole) {
            QVariant d=item->data(role);
            int w=16;
            if (d.type()==QVariant::Icon) {
                w=32;
            }
            QPixmap ic(QSize(w,16));

            ic.fill(Qt::transparent);
            {
                QPainter p(&ic);
                QPen pen(QApplication::palette("QWidget").color(QPalette::Mid));
                pen.setStyle(Qt::DotLine);
                p.setPen(pen);
                if (isLastInFolder(index)) {
                    p.drawLine(8,0,8,8);
                } else {
                    p.drawLine(8,0,8,17);
                }
                p.drawLine(8,8,15,8);

                if (d.type()==QVariant::Icon) {
                    p.drawPixmap(16,0,16,16, d.value<QIcon>().pixmap(QSize(16,16)));
                }
            }
            return  ic;
        }

        return item->data(role);
    }
    return QVariant();
}
Qt::ItemFlags QFPseudoTreeModel::flags(const QModelIndex &index) const
{
    if (!index.isValid())
        return 0;

    if (isFolder(index)) {
        return Qt::ItemIsEnabled;
    }


    return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
Beispiel #15
0
// display a right-click menu
void RSSWidget::displayRSSListMenu(const QPoint &pos)
{
    if (!m_rssTreeView->indexAt(pos).isValid())
        // No item under the mouse, clear selection
        m_rssTreeView->clearSelection();
    QMenu myRSSListMenu(this);
    const auto selectedItems = m_rssTreeView->selectionModel()->selectedRows();
    if (selectedItems.size() > 0) {
        myRSSListMenu.addAction(m_ui->actionUpdate);
        myRSSListMenu.addAction(m_ui->actionMarkItemsRead);
        myRSSListMenu.addSeparator();
        if (selectedItems.size() == 1) {
            if (!isStickyItem(selectedItems.first())) {
                myRSSListMenu.addAction(m_ui->actionRename);
                myRSSListMenu.addAction(m_ui->actionDelete);
                myRSSListMenu.addSeparator();
                if (isFolder(selectedItems.first()))
                    myRSSListMenu.addAction(m_ui->actionNewFolder);
            }
        }
        else {
            myRSSListMenu.addAction(m_ui->actionDelete);
            myRSSListMenu.addSeparator();
        }
        myRSSListMenu.addAction(m_ui->actionNewSubscription);
        if (!isFolder(selectedItems.first())) {
            myRSSListMenu.addSeparator();
            myRSSListMenu.addAction(m_ui->actionCopyFeedURL);
        }
    }
    else {
        myRSSListMenu.addAction(m_ui->actionNewSubscription);
        myRSSListMenu.addAction(m_ui->actionNewFolder);
        myRSSListMenu.addSeparator();
        myRSSListMenu.addAction(m_ui->actionUpdateAllFeeds);
    }
    myRSSListMenu.exec(QCursor::pos());
}
Beispiel #16
0
std::string FilePath::getExtension() const 
{
    if( isFolder() )
    {
        return "";
    }

    std::string::size_type index = _d->path.find_last_of( '.' );
    if( index != std::string::npos )
    {
        return _d->path.substr( index, 0xff );
    }

    return "";
}
Beispiel #17
0
QList<QTreeWidgetItem *> FeedListWidget::getAllOpenedFolders(QTreeWidgetItem *parent) const
{
    QList<QTreeWidgetItem *> openedFolders;
    int nbChildren = (parent ? parent->childCount() : topLevelItemCount());
    for (int i = 0; i < nbChildren; ++i) {
        QTreeWidgetItem *item (parent ? parent->child(i) : topLevelItem(i));
        if (isFolder(item) && item->isExpanded()) {
            QList<QTreeWidgetItem *> openedSubfolders = getAllOpenedFolders(item);
            if (!openedSubfolders.empty())
                openedFolders << openedSubfolders;
            else
                openedFolders << item;
        }
    }
    return openedFolders;
}
Beispiel #18
0
bool Unzip::createFolderIfNotExists(const std::string & path)
{
	std::string pathToCreate = path;
	if(isFolder(pathToCreate)){
		boost::algorithm::erase_tail(pathToCreate, 1);
	}

	boost::filesystem::path p(pathToCreate);
	bool ok = true;
	if(! boost::filesystem::exists(p)){
		if(boost::filesystem::create_directories(p) == false){
			ok = false;
		}
	}

	return ok;
}
Beispiel #19
0
bool BookmarksModel::createSubfolder(const QString &name)
{
    if (isFolder(name)) {
        return false;
    }

    QSqlQuery query;
    query.prepare("INSERT INTO folders (name, subfolder) VALUES (?, 'yes')");
    query.bindValue(0, name);
    if (!query.exec()) {
        return false;
    }

    emit subfolderAdded(name);
    mApp->sendMessages(Qz::AM_BookmarksChanged, true);
    return true;
}
Beispiel #20
0
QString DomItem::name()
{
    QString name;
    if (isFolder()) {
        name = domElement.attribute("name");
    } else if (isSiteReference()) {
        // Compare uuid with all sites and get site name
        QString uuid = domElement.attribute("uuid");
        QDomNodeList siteList = domElement.ownerDocument().elementsByTagName("site");
        for (int i=0; i<siteList.count(); i++) {
            QDomElement element = siteList.item(i).toElement();
            if (element.attribute("uuid") == uuid)
                name = element.attribute("name");
        }
    }
    return name;
}
Beispiel #21
0
QVariant ModelItem::data(int column) const {
    switch(column) {
    case TITLEID:
        return getTitle();
    case EXTENSIONID:
        return extension;
    case PATHID:
        return path;
    case FOLDERID:
        return isFolder();
    case TITLESCACHEID:
        return QVariant(*getTitlesCache());
    case STATEID:
        return getState() -> currStateValue();
    default:
        return QVariant();
    }
}
Beispiel #22
0
void ContentUI::showFilesOnPanel(const QString &name, EPanels panel)
{
    if(name == PARENT_FOLDER_SIGN)
    {
        performShowFiles(SDriveEngine::inst()->getContentMngr()->back(), name, EBackward, panel);
    }
    else
    {
        if(isFolder())
        {
            QString query(GET_FILES_IN_FOLDER);

            query += CommonTools::getIDFromURL(SDriveEngine::inst()->getContentMngr()->getCurrentFileInfo().self);
            query += (CONTENTS + MAX_RESULTS);

            performShowFiles(query, name, EForward, panel);
        }
    }
}
Beispiel #23
0
bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder)
{
    if (url.isEmpty() || title.isEmpty() || folder.isEmpty()) {
        return false;
    }

    QImage image = icon.pixmap(16, 16).toImage();
    if (image.isNull()) {
        image = IconProvider::emptyWebImage();
    }

    if (!isFolder(folder)) {
        createFolder(folder);
    }

    QSqlQuery query;
    query.prepare("INSERT INTO bookmarks (url, title, folder, icon) VALUES (?,?,?,?)");
    query.bindValue(0, url.toString());
    query.bindValue(1, title);
    query.bindValue(2, folder);
    QByteArray ba;
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    image.save(&buffer, "PNG");
    query.bindValue(3, buffer.data());
    query.exec();

    Bookmark bookmark;
    bookmark.id = query.lastInsertId().toInt();
    bookmark.url = url;
    bookmark.title = title;
    bookmark.folder = folder;
    bookmark.image = image;
    bookmark.inSubfolder = isSubfolder(bookmark.folder);

    setLastFolder(folder);

    emit bookmarkAdded(bookmark);
    mApp->sendMessages(Qz::AM_BookmarksChanged, true);
    return true;
}
Beispiel #24
0
// add a stream by a button
void RSSWidget::on_newFeedButton_clicked()
{
    // Ask for feed URL
    const QString clipText = qApp->clipboard()->text();
    const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : "http://";

    bool ok;
    QString newURL = AutoExpandableDialog::getText(
                this, tr("Please type a RSS feed URL"), tr("Feed URL:"), QLineEdit::Normal, defaultURL, &ok);
    if (!ok) return;

    newURL = newURL.trimmed();
    if (newURL.isEmpty()) return;

    // Determine destination folder for new item
    QModelIndex destIndex;
    QModelIndexList selectedIndexes = m_rssTreeView->selectionModel()->selectedRows();
    if (!selectedIndexes.empty()) {
        destIndex = selectedIndexes.first();
        if (!isFolder(destIndex))
            destIndex = destIndex.parent();
    }

    // Consider the case where the user clicked on Unread item
    RSS::Folder &destFolder =
            *(!destIndex.isValid() ? RSS::Manager::instance()->rootFolder()
                                   : static_cast<RSS::Folder *>(getItemPtr(destIndex)));

    try {
        RSS::Manager::instance()->addFeed(newURL, "", destFolder);
        // Expand destination folder to display new feed
        if (destIndex.isValid() && !isStickyItem(destIndex))
            m_rssTreeView->expand(destIndex);
        // As new RSS items are added synchronously, we can do the following here.
//        m_rssTreeWidget->setCurrentItem(id);
    }
    catch (const RuntimeError &err) {
        QMessageBox::warning(this, "qBittorrent", err.message(), QMessageBox::Ok);
    }
}
Beispiel #25
0
void RSSWidget::askNewFolder()
{
    bool ok;
    QString newName = AutoExpandableDialog::getText(
                this, tr("Please choose a folder name"), tr("Folder name:"), QLineEdit::Normal
                , tr("New folder"), &ok);
    if (!ok) return;

    newName = newName.trimmed();
    if (newName.isEmpty()) return;

    // Determine destination folder for new item
    QModelIndex destIndex;
    QModelIndexList selectedIndexes = m_rssTreeView->selectionModel()->selectedRows();
    if (!selectedIndexes.empty()) {
        destIndex = selectedIndexes.first();
        if (!isFolder(destIndex))
            destIndex = destIndex.parent();
    }
    // Consider the case where the user clicked on Unread item
    RSS::Folder &destFolder =
            *(!destIndex.isValid() ? RSS::Manager::instance()->rootFolder()
                                   : static_cast<RSS::Folder *>(getItemPtr(destIndex)));

    try {
        RSS::Manager::instance()->addFolder(newName, destFolder);
        // Expand destination folder to display new feed
        if (destIndex.isValid() && !isStickyItem(destIndex))
            m_rssTreeView->expand(destIndex);
        // As new RSS items are added synchronously, we can do the following here.
//        m_rssTreeWidget->setCurrentItem(id);
    }
    catch (const RuntimeError &err) {
        QMessageBox::warning(this, "qBittorrent", err.message(), QMessageBox::Ok);
    }
}
Beispiel #26
0
SxTrack* SxPlaylist::getTrack(int index) {
    if (index < getNumberOfTracks() && m_isValid && isLoaded() && !isFolder()) return m_tracks[index];
    return NULL;
}
Beispiel #27
0
bool Unzip::isFile(const std::string & path)
{
	return isFolder(path) == false;
}
Beispiel #28
0
void TupItemManager::mousePressEvent(QMouseEvent *event)
{
    parentNode = "";

    QTreeWidgetItem *item = itemAt(event->pos());

    if (item) {
        setCurrentItem(item);
        emit itemSelected(item);

        if (event->buttons() == Qt::RightButton) {
            QMenu *menu = new QMenu(tr("Options"));

            if (isFolder(item)) {
                QAction *rename = new QAction(tr("Rename"), this);
                connect(rename, SIGNAL(triggered()), this, SLOT(renameItem()));

                QAction *remove = new QAction(tr("Delete"), this);
                connect(remove, SIGNAL(triggered()), this, SIGNAL(itemRemoved()));

                menu->addAction(rename);
                menu->addAction(remove);
            } else {
                QString extension = item->text(2);
                bool isSound = false;
                bool isNative = false;

                if ((extension.compare("OGG") == 0) || (extension.compare("MP3") == 0) || (extension.compare("WAV") == 0))
                    isSound = true; 
                if (extension.compare("OBJ") == 0)
                    isNative = true; 

                if (extension.compare("SVG") == 0) {
                    QAction *edit = new QAction(tr("Edit with Inkscape"), this);
                    connect(edit, SIGNAL(triggered()), this, SLOT(callInkscapeToEdit()));
                    #ifdef Q_OS_UNIX
                        if (!QFile::exists("/usr/bin/inkscape"))
                            edit->setDisabled(true);
                    #else
                        edit->setDisabled(true);
                    #endif
                    menu->addAction(edit);
                } else if ((extension.compare("OBJ") != 0) && !isSound) {
                           QAction *gimpEdit = new QAction(tr("Edit with Gimp"), this);
                           connect(gimpEdit, SIGNAL(triggered()), this, SLOT(callGimpToEdit()));
                           #ifdef Q_OS_UNIX
                               if (!QFile::exists("/usr/bin/gimp"))
                                   gimpEdit->setDisabled(true);
                           #else
                               gimpEdit->setDisabled(true);
                           #endif
                           menu->addAction(gimpEdit);

                           QAction *kritaEdit = new QAction(tr("Edit with Krita"), this);
                           connect(kritaEdit, SIGNAL(triggered()), this, SLOT(callKritaToEdit()));
                           #ifdef Q_OS_UNIX
                               if (!QFile::exists("/usr/bin/krita"))
                                   kritaEdit->setDisabled(true);
                           #else
                                   kritaEdit->setDisabled(true);
                           #endif
                           menu->addAction(kritaEdit);

                           QAction *myPaintEdit = new QAction(tr("Edit with MyPaint"), this);
                           connect(myPaintEdit, SIGNAL(triggered()), this, SLOT(callMyPaintToEdit()));
                           #ifdef Q_OS_UNIX
                               if (!QFile::exists("/usr/bin/mypaint"))
                                   myPaintEdit->setDisabled(true);
                           #else
                               myPaintEdit->setDisabled(true);
                           #endif
                           menu->addAction(myPaintEdit);
                }

                if (!isSound && !isNative) {
                    QAction *clone = new QAction(tr("Clone"), this);
                    connect(clone, SIGNAL(triggered()), this, SLOT(cloneItem()));
                    menu->addAction(clone);
                }

                QAction *exportObject = new QAction(tr("Export"), this);
                connect(exportObject, SIGNAL(triggered()), this, SLOT(exportItem()));

                QAction *rename = new QAction(tr("Rename"), this);
                connect(rename, SIGNAL(triggered()), this, SLOT(renameItem()));

                QAction *remove = new QAction(tr("Delete"), this);
                connect(remove, SIGNAL(triggered()), this, SIGNAL(itemRemoved()));

                menu->addAction(exportObject);
                menu->addAction(rename);
                menu->addAction(remove);
                menu->addSeparator();

                #ifdef Q_OS_UNIX
                    if (!isSound) {
                        if (QFile::exists("/usr/bin/gimp") || QFile::exists("/usr/bin/krita") || QFile::exists("/usr/bin/mypaint")) {
                            QAction *raster = new QAction(tr("Create new raster item"), this);
                            connect(raster, SIGNAL(triggered()), this, SLOT(createNewRaster()));
                            menu->addAction(raster);
                        }

                        if (QFile::exists("/usr/bin/inkscape")) {
                            QAction *svg = new QAction(tr("Create new svg item"), this);
                            connect(svg, SIGNAL(triggered()), this, SLOT(createNewSVG()));
                            menu->addAction(svg);
                        }
                    }
                #endif
            }

            menu->exec(event->globalPos());
        } else if (event->buttons() == Qt::LeftButton) {
                   // SQA: This code doesn't work well at all. Reengineering is urgently required right here!
                   // If the node has a parent, get the parent's name
                   QTreeWidgetItem *top = item->parent(); 
                   if (top)
                       parentNode = top->text(1);

                   // For directories, get the children
                   nodeChildren.clear();
                   if (item->text(2).length()==0 && item->childCount() > 0) {
                       for (int i=0;i<item->childCount();i++) {
                            QTreeWidgetItem *node = item->child(i);
                            nodeChildren << node;
                       }
                   } 

                   QPixmap pixmap = item->icon(0).pixmap(15, 15);

                   QByteArray itemData;
                   QDataStream dataStream(&itemData, QIODevice::WriteOnly);
                   dataStream << pixmap << item->text(1) << item->text(2) << item->text(3);

                   QMimeData *mimeData = new QMimeData;
                   mimeData->setData("application/x-dnditemdata", itemData);

                   QDrag *drag = new QDrag(this);
                   drag->setMimeData(mimeData);
                   drag->setPixmap(pixmap);

                   if (drag->start(Qt::MoveAction) == Qt::MoveAction)
                       delete takeTopLevelItem(indexOfTopLevelItem(item));
        }
    } else {
        if (event->buttons() == Qt::RightButton) {
            QMenu *menu = new QMenu(tr("Options"));

            #ifdef Q_OS_UNIX
            if (QFile::exists("/usr/bin/gimp") || QFile::exists("/usr/bin/krita") || QFile::exists("/usr/bin/mypaint")) {
                QAction *raster = new QAction(tr("Create new raster item"), this);
                connect(raster, SIGNAL(triggered()), this, SLOT(createNewRaster()));
                menu->addAction(raster);
            }
            if (QFile::exists("/usr/bin/inkscape")) {
                QAction *svg = new QAction(tr("Create new svg item"), this);
                connect(svg, SIGNAL(triggered()), this, SLOT(createNewSVG()));
                menu->addAction(svg);
            }
            #endif

            menu->exec(event->globalPos());
        }
    }
}
void BookmarksDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if(!mViewPtr)
        return;

    painter->save();
    QColor bkgrColor = QColor(0xAA,0xAA,0xAA);
    QColor folderColor = QColor(0x33, 0x33, 0x33);

    QPen borderPen(bkgrColor.darker());
    if(!isFolder(index))
    {
        QRadialGradient itemGradient(0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top(), 0.8*(qreal)option.rect.width(), 0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top());
        itemGradient.setColorAt(0.0, Qt::white);
        itemGradient.setColorAt(1.0, bkgrColor);

        if(isLast(index))
        {
            QPainterPath endPath;
            endPath.moveTo(option.rect.topLeft());
            endPath.lineTo(option.rect.bottomLeft()-QPoint(0, RADIUS));
            endPath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 180, 90);
            endPath.lineTo(option.rect.bottomRight()-QPoint(RADIUS, 0));
            endPath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, 90);
            endPath.lineTo(option.rect.topRight());

            //painter->setBrush( bkgrColor );
            painter->setBrush(itemGradient);
            painter->setPen(borderPen);
            painter->drawPath(endPath);
        }
        else // middle elements
        {
            //painter->setBrush( bkgrColor );
            painter->setBrush(itemGradient);
            painter->setPen(Qt::NoPen);
            painter->drawRect(option.rect);

            painter->setPen(borderPen);
            // vertical lines
            painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
            painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
            // horizontal lines
            painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
        }

        QRectF brect = option.rect;
        brect.setLeft(brect.left()+SPACER);
        painter->setFont(option.font);
        painter->drawText(brect, Qt::AlignVCenter, qVariantValue<QString>(index.data()));
    }
    else // doesn't have parent
    {
        QRadialGradient itemGradient(0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top(), 0.8*(qreal)option.rect.width(), 0.3*(qreal)option.rect.width()+option.rect.left(), -2*(qreal)option.rect.height()+option.rect.top());
        itemGradient.setColorAt(0.0, Qt::white);
        itemGradient.setColorAt(1.0, folderColor);

        QPainterPath titlePath;
        if(isExpanded(index))
        {
            titlePath.moveTo(option.rect.bottomLeft());
            titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
            titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
            titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
            titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
            titlePath.lineTo(option.rect.bottomRight());
            titlePath.closeSubpath();
        }
        else
        {
            titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
            titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
            titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
            titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
            titlePath.lineTo(option.rect.bottomRight()-QPoint(0, RADIUS));
            titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 0, -90);
            titlePath.lineTo(option.rect.bottomLeft()+QPoint(RADIUS, 0));
            titlePath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, -90);
            titlePath.closeSubpath();
        }

        painter->setBrush(itemGradient);
        painter->setPen(borderPen);
        painter->drawPath(titlePath);

        QRectF brect = option.rect;
        brect.setLeft(brect.left()+SPACER);
        painter->setFont(option.font);
        painter->drawText(brect, Qt::AlignVCenter, qVariantValue<QString>(index.data()));
    }

    //// HIGHLIGHTING SELECTED ITEM
    //if (option.state & QStyle::State_Selected)
        //painter->fillRect(option.rect, option.palette.highlight());

    painter->restore();
}
Beispiel #30
0
int extractFiles(FILE *f, Context *cnt) {
  char **files = cnt->workFiles;
  int64_t *count = NULL;
  char *res = NULL;
  char *currentFile = NULL;
  int64_t len = 0;
  int64_t i = 0;
  ArchFileInfo aFileInfo;
  FileInfo fInfo;
  int shifted = 0;
  int _error = 0;
  fpos_t archPos;
  bool isEof = 0;
  struct stat st = {0};
  LOGGING_FUNC_START;

  _error = f ? 0 : (__forErrorFileName = cnt->archName, OPEN_ARCHIVE_FILE_ERROR);
  ERROR_CHECK_NOT_LOOP;

  for (len=0; *(files+len); len++) {
    res = *(files + len);
    *(files + len) = pathToCanon(res);
  }

  count = calloc(len,sizeof(int64_t));

  INFO(L"NFiles:%d", len);
  aFileInfo.fileInfo = &fInfo;

  while (!isEof) {
    _error = readHeader(f, &aFileInfo);
    ERROR_CHECK;

    INFO(L"File in arch: %s", aFileInfo.fileInfo->name);

    shifted = 0;

    for (i=0; i<len; i++) {
      if ((*(files + i)) &&
          (pathInDest(*(files + i), aFileInfo.fileInfo->name))) {
        currentFile = getFileByPathWithFolder/*getFileByPath*/(*(files + i), aFileInfo.fileInfo->name);
        INFO(L"Current file: `%s`", currentFile);
        if (isFolder(currentFile)) {
          INFO(L"Folder");
          if (-1 == stat(currentFile, &st)) {
            currentFile[max((int64_t) strlen(currentFile)-2, 0)] = 0;
            INFO(L"Try to create folder `%s`", currentFile);
            printf("Create folder `%s`\n", currentFile);
            _error = mkdir(currentFile, 0777);
            INFO(L"Folder create with error `%d`", _error);
            _error = _error ? (__forErrorFileName = currentFile, MKDIR_ERROR) : 0 ;
            ERROR_CHECK;
            _error = 0;
          }
          shifted = 1;
        } else {
          IO(L"Extract `%s` to `%s`", aFileInfo.fileInfo->name, currentFile);
          printf("Extract `%s` to `%s`\n", aFileInfo.fileInfo->name, currentFile);
          _error = extract(f, &aFileInfo, currentFile);
          INFO(L"Extract with error `%d`", _error);
          ERROR_CHECK;
          shifted = 1;
          count[i]++;
        }
        free(currentFile);
        currentFile = NULL;
      }
    }


    _error = fseek(f, (shifted ? 0 : (aFileInfo.dataSize))  + sizeof(crc), SEEK_CUR);
    INFO(L"fseek with error `%d`", _error);
    _error = _error ? (__forErrorFileName = cnt->archName ,FSEEK_ERROR) : 0;
    INFO("Position %d", (fgetpos(f, &archPos), archPos));
    INFO("==========================");
  }

  for (i=0; i<len; i++) {
    if (!count[i]) {
      __forErrorFileName = files[i];
      msg(INCORRECT_FILE_NAME);
    }
  }

  free(count);

  LOGGING_FUNC_STOP;
  return 0;
}