Logo Search packages:      
Sourcecode: basket version File versions  Download package

void Basket::save (  )  [slot]

Save & load work

Definition at line 2528 of file basket.cpp.

References Global::debugWindow, icon(), and Item::next().

Referenced by ItemFactory::createItemText(), and ItemFactory::dropItem().

{
      if (Global::debugWindow)
            *Global::debugWindow << "Basket : save properties";

      // Create document
      QDomDocument doc("basket");
      QDomElement root = doc.createElement("basket");
      doc.appendChild(root);

      // Create properties element and populate it
      QDomElement properties = doc.createElement("properties");
      root.appendChild(properties);

      XMLWork::addElement( doc, properties, "name", name() );
      XMLWork::addElement( doc, properties, "icon", icon() );

      QDomElement background = doc.createElement("background");
      properties.appendChild(background);
      background.setAttribute( "color",    m_color.name()    );
      background.setAttribute( "altColor", m_altColor.name() );

      XMLWork::addElement( doc, properties, "showCheckBoxes", XMLWork::trueOrFalse(showCheckBoxes()) );
      XMLWork::addElement( doc, properties, "showSearchBar",  XMLWork::trueOrFalse(showSearchBar())  );

      QDomElement align = doc.createElement("alignment");
      properties.appendChild(align);
      align.setAttribute( "hor", QString::number(hAlign()) );
      align.setAttribute( "ver", QString::number(vAlign()) );

      XMLWork::addElement( doc, properties, "locked", XMLWork::trueOrFalse(isLocked()) );

      QDomElement additempolicy = doc.createElement("addItemPolicy");
      properties.appendChild(additempolicy);
      additempolicy.setAttribute( "insertAtEnd",       XMLWork::trueOrFalse( m_insertAtEnd       ) );
      additempolicy.setAttribute( "insertAtCursorPos", XMLWork::trueOrFalse( m_insertAtCursorPos ) );

      QDomElement vfc = doc.createElement("viewFileContent");
      properties.appendChild(vfc);
      vfc.setAttribute( "text",  XMLWork::trueOrFalse(viewFileContent(FileText))  );
      vfc.setAttribute( "HTML",  XMLWork::trueOrFalse(viewFileContent(FileHTML))  );
      vfc.setAttribute( "image", XMLWork::trueOrFalse(viewFileContent(FileImage)) );
      vfc.setAttribute( "sound", XMLWork::trueOrFalse(viewFileContent(FileSound)) );

      QDomElement stack = doc.createElement("stack");
      properties.appendChild(stack);
      stack.setAttribute( "activated",      XMLWork::trueOrFalse( m_isAStack            ) );
      stack.setAttribute( "takeOnSameSide", XMLWork::trueOrFalse( m_stackTakeOnSameSide ) );
      stack.setAttribute( "afterDrag",      QString::number(      m_stackAfterDrag      ) );

      if (isAClipboard()) {
            QDomElement clipboard = doc.createElement("clipboard");
            properties.appendChild(clipboard);
            clipboard.setAttribute( "activated", "true"              );
            clipboard.setAttribute( "maxItems",  m_clipboardMaxItems );
            clipboard.setAttribute( "which",     m_clipboardWhich    );
      }

      // Save it, in case of another computer would mirror it ???
      QDomElement mirror = doc.createElement("mirror");
      properties.appendChild(mirror);
      mirror.setAttribute( "onlyNewFiles", XMLWork::trueOrFalse(m_mirrorOnlyNewFiles) );

      QDomElement onClick = doc.createElement("onClick");
      properties.appendChild(onClick);
      onClick.setAttribute( "content", m_contentOnClickAction );
      onClick.setAttribute( "file",    m_fileOnClickAction    );

      // Create items element and populate it
      QDomElement items = doc.createElement("items");

      for (Item *it = firstItem(); it != 0L; it = it->next()) {
            QDomElement content = doc.createElement("content");
            QDomText cont;
            switch (it->type()) {
                  case Item::Text:
                        content.setAttribute( "font", QString::number(it->textFontType()) );
                        content.setAttribute( "color", it->textColor().name() );
                        cont = doc.createTextNode( it->fileName() );
                        break;
                  case Item::Html:
//                      content.setAttribute( "showSource", XMLWork::trueOrFalse(it->showSource()) );
                        cont = doc.createTextNode( it->fileName() );
                        break;
                  case Item::Image:
                  case Item::Animation:
                  case Item::Sound:
                  case Item::File:
                  case Item::Launcher:
                  case Item::Unknow:
                        cont = doc.createTextNode( it->fileName() );
                        break;
                  case Item::Link:
                        content.setAttribute( "title",                          it->title()      );
                        content.setAttribute( "icon",                           it->icon()       );
                        content.setAttribute( "autoTitle", XMLWork::trueOrFalse(it->autoTitle()) );
                        content.setAttribute( "autoIcon",  XMLWork::trueOrFalse(it->autoIcon())  );
                        cont = doc.createTextNode( it->url().prettyURL() );
                        break;
                  case Item::Color:
                        cont = doc.createTextNode( it->color().name() );
                        break;
            }
            content.appendChild(cont);
            QDomElement item = doc.createElement("item");
            items.appendChild(item);
            item.setAttribute( "type", it->lowerTypeName() );
            item.setAttribute( "checked", XMLWork::trueOrFalse(it->isChecked()) );

            item.appendChild(content);

            if ( ! it->annotations().isEmpty() )
                  XMLWork::addElement( doc, item, "annotations", it->annotations() );
      }

      root.appendChild(items);

      QFile file(fullPath() + ".basket");
      if ( file.open(IO_WriteOnly) ) {
            QTextStream stream(&file);
            stream.setEncoding(QTextStream::UnicodeUTF8);
            QString xml = doc.toString();
            stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
            stream << xml;
            file.close();
      }
}


Generated by  Doxygen 1.6.0   Back to index