Ejemplo n.º 1
0
QString BasketFactory::unpackTemplate(const QString &templateName)
{
    // Find a name for a new folder and create it:
    QString folderName = newFolderName();
    QString fullPath   = Global::basketsFolder() + folderName;
    QDir dir;
    if (!dir.mkdir(fullPath)) {
        KMessageBox::error(/*parent=*/0, i18n("Sorry, but the folder creation for this new basket has failed."), i18n("Basket Creation Failed"));
        return "";
    }

    // Unpack the template file to that folder:
    // TODO: REALLY unpack (this hand-creation is temporary, or it could be used in case the template can't be found)
    QFile file(fullPath + "/.basket");
    if (file.open(QIODevice::WriteOnly)) {
        QTextStream stream(&file);
        stream.setCodec("UTF-8");
        int nbColumns = (templateName == "mindmap" || templateName == "free" ? 0 : templateName.left(1).toInt());
        BasketScene *currentBasket = Global::bnpView->currentBasket();
        int columnWidth = (currentBasket && nbColumns > 0 ? (currentBasket->graphicsView()->viewport()->width() - (nbColumns - 1) * Note::RESIZER_WIDTH) / nbColumns : 0);
        stream << QString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
                          "<!DOCTYPE basket>\n"
                          "<basket>\n"
                          " <properties>\n"
                          "  <disposition mindMap=\"%1\" columnCount=\"%2\" free=\"%3\" />\n"
                          " </properties>\n"
                          " <notes>\n").arg((templateName == "mindmap" ? "true" : "false"),
                                            QString::number(nbColumns),
                                            (templateName == "free" || templateName == "mindmap" ? "true" : "false"));
        if (nbColumns > 0)
            for (int i = 0; i < nbColumns; ++i)
                stream << QString("  <group width=\"%1\"></group>\n").arg(columnWidth);
        stream << " </notes>\n"
        "</basket>\n";
        file.close();
        return folderName;
    } else {
        KMessageBox::error(/*parent=*/0, i18n("Sorry, but the template copying for this new basket has failed."), i18n("Basket Creation Failed"));
        return "";
    }
}
Ejemplo n.º 2
0
void FileOrganiserWidget::newFolder()
{
    if (!canCreateNewFolder())
        // The conditions are not met to create a new folder, so...

        return;

    // Either create a folder item below the current folder item or below the
    // root item, depending on the situation

    QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
    int selectedIndexesCount = selectedIndexes.count();
    QStandardItem *crtItem = !selectedIndexesCount?
                                mModel->invisibleRootItem():
                                mModel->itemFromIndex(selectedIndexes.first());
    QStandardItem *newFolderItem = new QStandardItem(QIcon(CollapsedFolderIcon),
                                                     newFolderName(crtItem));

    newFolderItem->setData(true, Item::Folder);

    crtItem->appendRow(newFolderItem);

    // Some post-processing, but only if no other item is currently being edited

    if (!isEditing()) {
        // Expand the current index (so that we can see the new folder)
        // Note: this is only relevant in the case of a folder item being
        //       currently selected (i.e. it's not the root folder item)

        if (selectedIndexesCount)
            setExpanded(crtItem->index(), true);

        // Offer the user to edit the newly added folder item

        edit(newFolderItem->index());
    }

    // Resize the widget, just to be on the safe side

    resizeToContents();
}