Esempio n. 1
0
void TagsPage::addTags(int index, std::string str) {
  auto& data = wizard_->app()->data();
  if (index >= options_.size()) {
    tags_->addItem(str);
    data.used_tags.push_back(str);
  } else {
    //if (index) str.push_back(' ');
    int sel = options_[index]->getCurSel();
    if (sel >= 0) sel = options_[index]->getItemData(sel);
    if (sel < 0) {
      //for (auto const& tag : data.tags[index]) {
      //  addTags(index + 1, str + tag);
      //}
      addTags(index + 1, str);
    } else {
      std::string next = str;
      if (!str.empty()) next.push_back(' ');
      addTags(index + 1, next + data.tags[index][sel]);
    }
  }
}
void CollectiontagsModel::change(const QString& id, const QVariantMap& data) {
    if (data.value(QLatin1String("type_")).toString() != QLatin1String("collection"))
        return;

    const QVariantList variantList = data.value(QLatin1String("categories")).toList();
    QList<QString> tags;
    QListIterator<QVariant> i(variantList);
    while (i.hasNext()) {
        tags << i.next().toString();
    }
    checkAndRemoveTags(id, tags);
    addTags(id, tags);
}
Esempio n. 3
0
LRESULT TagsPage::onMessage(uint32 message, WPARAM wParam, LPARAM lParam) {
  auto& data = wizard_->app()->data();
  switch (message) {
  case WM_NOTIFY:
    if (((NMHDR*) lParam)->code == LVN_ITEMCHANGED) {
      int sel = tags_->getCurSel();
      remove_->enable(sel >= 0);
    }
    return 0;
  case WM_COMMAND:
    if (LOWORD(wParam) == ID_ADD && HIWORD(wParam) == BN_CLICKED) {
      addTags(0, "");
      size_->setText("Total size: " + formatSize(data.downloadSize()));
    } else if (LOWORD(wParam) == ID_REMOVE && HIWORD(wParam) == BN_CLICKED) {
      int pos;
      while ((pos = tags_->getCurSel()) >= 0) {
        ListView_DeleteItem(tags_->getHandle(), pos);
        data.used_tags.erase(data.used_tags.begin() + pos);
      }
      size_->setText("Total size: " + formatSize(data.downloadSize()));
    }
    return 0;
  case WM_TASKDONE:
    if (lParam == -1) {
      loading_->hide();
      note_->setText("Failed to load build tags");
    } else if (lParam == ProgramData::LOADING + 0 || lParam == ProgramData::LOADING + 1) {
      if (lParam == ProgramData::LOADING + 0) {
        note_->setText("Fetching encoding table...");
      } else {
        note_->setText("Fetching download list...");
      }
      loading_->setRange(0, data.loading_size);
      loading_->setPos(data.loading_progress);
      loading_->show(data.loading_progress < data.loading_size);
    } else {
      loading_->hide();
      note_->setText("Select build tags:");
      int curWidth = 1000;
      Frame* prevBox = note_;
      Frame* prevLine = note_;
      for (auto const& tags : data.tags) {
        int maxWidth = std::max<int>(60, FontSys::getTextSize(FontSys::getSysFont(), "Any").cx);
        ComboFrame* box = new ComboFrame(this);
        options_.push_back(box);
        if (tags.size() > 0) {
          box->addString("Any", -1);
        }
        for (size_t i = 0; i < tags.size(); ++i) {
          box->addString(tags[i], i);
          maxWidth = std::max<int>(maxWidth, FontSys::getTextSize(FontSys::getSysFont(), tags[i]).cx);
        }
        box->setCurSel(0);
        box->setWidth(maxWidth + 20);
        if (curWidth + maxWidth + 28 > 300) {
          box->setPoint(PT_TOPLEFT, prevLine, PT_BOTTOMLEFT, 0, 8);
          prevLine = box;
          curWidth = maxWidth + 20;
        } else {
          box->setPoint(PT_BOTTOMLEFT, prevBox, PT_BOTTOMRIGHT, 8, 0);
          curWidth += maxWidth + 28;
        }
        prevBox = box;
      }

      ButtonFrame* btn = new ButtonFrame("+", this, ID_ADD);
      btn->setSize(21, 21);
      btn->setPoint(PT_TOPRIGHT, note_, PT_BOTTOMLEFT, -8, 8);

      size_ = new StaticFrame("Total size", this);
      size_->setPoint(PT_LEFT, note_, PT_LEFT, 0, 0);
      size_->setPoint(PT_BOTTOMRIGHT, 0, 0);

      tags_ = new ListFrame(this);
      tags_->setPoint(PT_TOPLEFT, prevLine, PT_BOTTOMLEFT, 0, 8);
      tags_->setPoint(PT_BOTTOMRIGHT, size_, PT_TOPRIGHT, 0, -8);

      remove_ = new ButtonFrame("-", this, ID_REMOVE);
      remove_->setSize(21, 21);
      remove_->setPoint(PT_TOPRIGHT, tags_, PT_TOPLEFT, -8, 0);
      remove_->disable();

      if (data.used_tags.size()) {
        for (std::string const& tag : data.used_tags) {
          tags_->addItem(tag);
        }
      }
      size_->setText("Total size: " + formatSize(data.downloadSize()));
      wizard_->enableNext(true);
    }
    return 0;
  default:
    return M_UNHANDLED;
  }
}
Esempio n. 4
0
File: Task.cpp Progetto: nigeil/task
////////////////////////////////////////////////////////////////////////////////
// Support FF2, FF3.
// Thankfully FF1 is no longer supported.
void Task::legacyParse (const std::string& line)
{
  switch (determineVersion (line))
  {
  // File format version 1, from 2006.11.27 - 2007.12.31
  case 1:
    throw std::string (STRING_TASK_NO_FF1);
    break;

  // File format version 2, from 2008.1.1 - 2009.3.23
  case 2:
    {
      if (line.length () > 46)       // ^.{36} . \[\] \[\] \n
      {
        set ("uuid", line.substr (0, 36));

        Task::status status = line[37] == '+' ? completed
                            : line[37] == 'X' ? deleted
                            : line[37] == 'r' ? recurring
                            :                   pending;

        set ("status", statusToText (status));

        size_t openTagBracket  = line.find ("[");
        size_t closeTagBracket = line.find ("]", openTagBracket);
        if (openTagBracket  != std::string::npos &&
            closeTagBracket != std::string::npos)
        {
          size_t openAttrBracket  = line.find ("[", closeTagBracket);
          size_t closeAttrBracket = line.find ("]", openAttrBracket);
          if (openAttrBracket  != std::string::npos &&
              closeAttrBracket != std::string::npos)
          {
            std::string tags = line.substr (
              openTagBracket + 1, closeTagBracket - openTagBracket - 1);
            std::vector <std::string> tagSet;
            split (tagSet, tags, ' ');
            addTags (tagSet);

            std::string attributes = line.substr (
              openAttrBracket + 1, closeAttrBracket - openAttrBracket - 1);
            std::vector <std::string> pairs;
            split (pairs, attributes, ' ');
            for (size_t i = 0; i <  pairs.size (); ++i)
            {
              std::vector <std::string> pair;
              split (pair, pairs[i], ':');
              if (pair.size () == 2)
                set (pair[0], pair[1]);
            }

            set ("description", line.substr (closeAttrBracket + 2));
          }
          else
            throw std::string (STRING_TASK_PARSE_ATT_BRACK);
        }
        else
          throw std::string (STRING_TASK_PARSE_TAG_BRACK);
      }
      else
        throw std::string (STRING_TASK_PARSE_TOO_SHORT);

      removeAnnotations ();
    }
    break;

  // File format version 3, from 2009.3.23
  case 3:
    {
      if (line.length () > 49)       // ^.{36} . \[\] \[\] \[\] \n
      {
        set ("uuid", line.substr (0, 36));

        Task::status status = line[37] == '+' ? completed
                            : line[37] == 'X' ? deleted
                            : line[37] == 'r' ? recurring
                            :                   pending;

        set ("status", statusToText (status));

        size_t openTagBracket  = line.find ("[");
        size_t closeTagBracket = line.find ("]", openTagBracket);
        if (openTagBracket  != std::string::npos &&
            closeTagBracket != std::string::npos)
        {
          size_t openAttrBracket  = line.find ("[", closeTagBracket);
          size_t closeAttrBracket = line.find ("]", openAttrBracket);
          if (openAttrBracket  != std::string::npos &&
              closeAttrBracket != std::string::npos)
          {
            size_t openAnnoBracket  = line.find ("[", closeAttrBracket);
            size_t closeAnnoBracket = line.find ("]", openAnnoBracket);
            if (openAnnoBracket  != std::string::npos &&
                closeAnnoBracket != std::string::npos)
            {
              std::string tags = line.substr (
                openTagBracket + 1, closeTagBracket - openTagBracket - 1);
              std::vector <std::string> tagSet;
              split (tagSet, tags, ' ');
              addTags (tagSet);

              std::string attributes = line.substr (
                openAttrBracket + 1, closeAttrBracket - openAttrBracket - 1);
              std::vector <std::string> pairs;
              split (pairs, attributes, ' ');

              for (size_t i = 0; i <  pairs.size (); ++i)
              {
                std::vector <std::string> pair;
                split (pair, pairs[i], ':');
                if (pair.size () == 2)
                  set (pair[0], pair[1]);
              }

              // Extract and split the annotations, which are of the form:
              //   1234:"..." 5678:"..."
              std::string annotations = line.substr (
                openAnnoBracket + 1, closeAnnoBracket - openAnnoBracket - 1);
              pairs.clear ();

              std::string::size_type start = 0;
              std::string::size_type end   = 0;
              do
              {
                end = annotations.find ('"', start);
                if (end != std::string::npos)
                {
                  end = annotations.find ('"', end + 1);

                  if (start != std::string::npos &&
                      end   != std::string::npos)
                  {
                    pairs.push_back (annotations.substr (start, end - start + 1));
                    start = end + 2;
                  }
                }
              }
              while (start != std::string::npos &&
                     end   != std::string::npos);

              for (size_t i = 0; i < pairs.size (); ++i)
              {
                std::string pair = pairs[i];
                std::string::size_type colon = pair.find (":");
                if (colon != std::string::npos)
                {
                  std::string name = pair.substr (0, colon);
                  std::string value = pair.substr (colon + 2, pair.length () - colon - 3);
                  set ("annotation_" + name, value);
                  ++annotation_count;
                }
              }

              set ("description", line.substr (closeAnnoBracket + 2));
            }
            else
              throw std::string (STRING_TASK_PARSE_ANNO_BRACK);
          }
          else
            throw std::string (STRING_TASK_PARSE_ATT_BRACK);
        }
        else
          throw std::string (STRING_TASK_PARSE_TAG_BRACK);
      }
      else
        throw std::string (STRING_TASK_PARSE_TOO_SHORT);
    }
    break;

  default:
    throw std::string (STRING_TASK_PARSE_UNREC_FF);
    break;
  }

  recalc_urgency = true;
}