Exemplo n.º 1
0
void KACLListView::slotEditEntry()
{
    QTreeWidgetItem * current = currentItem();
    if ( !current ) return;
    KACLListViewItem *item = static_cast<KACLListViewItem*>( current );
    int allowedTypes = item->type | NamedUser | NamedGroup;
    bool itemWasMask = item->type == Mask;
    if ( !m_hasMask || itemWasMask )
        allowedTypes |= Mask;
    int allowedDefaultTypes = item->type | NamedUser | NamedGroup;
    if ( !findDefaultItemByType( Mask ) )
        allowedDefaultTypes |=  Mask;
    if ( !hasDefaultEntries() )
        allowedDefaultTypes |= User | Group;

    EditACLEntryDialog dlg( this, item,
                            allowedUsers( false, item ), allowedGroups( false, item ),
                            allowedUsers( true, item ), allowedGroups( true, item ),
                            allowedTypes, allowedDefaultTypes, m_allowDefaults );
    dlg.exec();
    if ( itemWasMask && item->type != Mask ) {
        m_hasMask = false;
        m_mask = 0;
    }
    if ( !itemWasMask && item->type == Mask ) {
        m_mask = item->value;
        m_hasMask = true;
    }
    calculateEffectiveRights();
    sortItems( sortColumn(), Qt::AscendingOrder );
}
Exemplo n.º 2
0
void KACLListView::slotAddEntry()
{
    int allowedTypes = NamedUser | NamedGroup;
    if ( !m_hasMask )
        allowedTypes |= Mask;
    int allowedDefaultTypes = NamedUser | NamedGroup;
    if ( !findDefaultItemByType( Mask ) )
        allowedDefaultTypes |=  Mask;
    if ( !hasDefaultEntries() )
        allowedDefaultTypes |= User | Group;
    EditACLEntryDialog dlg( this, 0,
                            allowedUsers( false ), allowedGroups( false ),
                            allowedUsers( true ), allowedGroups( true ),
                            allowedTypes, allowedDefaultTypes, m_allowDefaults );
    dlg.exec();
    KACLListViewItem *item = dlg.item();
    if ( !item ) return; // canceled
    if ( item->type == Mask && !item->isDefault ) {
        m_hasMask = true;
        m_mask = item->value;
    }
    if ( item->isDefault && !hasDefaultEntries() ) {
        // first default entry, fill in what is needed
        if ( item->type != User ) {
            unsigned short v = findDefaultItemByType( User )->value;
            new KACLListViewItem( this, User, v, true );
        }
        if ( item->type != Group ) {
            unsigned short v = findDefaultItemByType( Group )->value;
            new KACLListViewItem( this, Group, v, true );
        }
        if ( item->type != Others ) {
            unsigned short v = findDefaultItemByType( Others )->value;
            new KACLListViewItem( this, Others, v, true );
        }
    }
    const KACLListViewItem *defaultMaskItem = findDefaultItemByType( Mask );
    if ( item->isDefault && !defaultMaskItem ) {
        unsigned short v = calculateMaskValue( true );
        new KACLListViewItem( this, Mask, v, true );
    }
    if ( !item->isDefault && !m_hasMask &&
            ( item->type == Group
              || item->type == NamedUser
              || item->type == NamedGroup ) ) {
        // auto-add a mask entry
        unsigned short v = calculateMaskValue( false );
        new KACLListViewItem( this, Mask, v, false );
        m_hasMask = true;
        m_mask = v;
    }
    calculateEffectiveRights();
    sortItems( sortColumn(), Qt::AscendingOrder );
    setCurrentItem( item );
    // QTreeWidget doesn't seem to emit, in this case, and we need to update
    // the buttons...
    if ( topLevelItemCount() == 1 )
        emit currentItemChanged( item, item );
}
Exemplo n.º 3
0
Settings::Settings(int argc, char **argv)
{
  try {
    TCLAP::CmdLine cmd("", ' ', VERSION_STRING, true);
    std::string    fmtrMsg = std::string("Output formatter type: ");
    
    /* Constraint definitions. */
    FormatConstraint         allowedFmt(nullStrVec);
    YearConstraint           allowedYear(nullIntVec);
    std::vector<std::string> allowedGroupsVec;
    std::vector<std::string> allowedIncrsVec;
    std::vector<std::string> allowedFmatrsVec;
    
    /* Output group values. */
    allowedGroupsVec.push_back("basic");
    allowedGroupsVec.push_back("struct");
    allowedGroupsVec.push_back("doxygen");
    allowedGroupsVec.push_back("all");
    TCLAP::ValuesConstraint<std::string> allowedGroups(allowedGroupsVec);
    
    /* Incrementation constraint values. */
    allowedIncrsVec.push_back("simple");
    allowedIncrsVec.push_back("date");
    allowedIncrsVec.push_back("months");
    allowedIncrsVec.push_back("years");
    TCLAP::ValuesConstraint<std::string> allowedIncrs(allowedIncrsVec);
    
    /* Formatter constraint values. */
    {
      size_t cnt = FormatterFactory::size();

      for (FormatterFnMap::iterator it = FormatterFactory::begin();
           it != FormatterFactory::end();
           ++it)
      {
        allowedFmatrsVec.push_back(it->first);
        fmtrMsg += it->first + " = "
            + FormatterFactory::nameForFormatter(it->first);

        if (cnt > 1) {
          fmtrMsg += ", ";
        }
      }
    }
    TCLAP::ValuesConstraint<std::string> allowedFmtrs(allowedFmatrsVec);
    
    /* Arguments. */
    StringOpt fileName("o",
                       "output",
                       "File containing version information.",
                       false,
                       "",
                       "string");
    StringOpt verFmt("f",
                     "format",
                     "Version number format string.",
                     false,
                     "*.*.+.*",
                     &allowedFmt);
    IntOpt baseYear("y",
                    "base-year",
                    "The year the project was started.",
                    false,
                    0,
                    &allowedYear);
    StringOpt incrType("i",
                       "increment",
                       "Type of increment used.",
                       false,
                       "simple",
                       &allowedIncrs);
    TCLAP::SwitchArg overFlow("s",
                              "overflow",
                              "Perform overflow checking and shifting.",
                              false);
    TCLAP::SwitchArg verbose("v",
                             "verbose",
                             "Verbose output.",
                             false);
    TCLAP::SwitchArg createFile("c",
                                "create",
                                "Create the output file if it does not exist.",
                                false);
    StringOpt formatter("t",
                        "formatter",
                        fmtrMsg,
                        true,
                        "",
                        &allowedFmtrs);
    TCLAP::MultiArg<std::string> groups("g",
                                        "groups",
                                        "Output groups generated.",
                                        false,
                                        &allowedGroups);
    StringOpt outPref("p",
                      "prefix",
                      "String to prepend to symbols created by the formatter.",
                      false,
                      "",
                      "string");
    
    /* Add them in reverse alphabetic order. */
    cmd.add(baseYear);          // y
    cmd.add(verbose);           // v
    cmd.add(formatter);         // t
    cmd.add(overFlow);          // s
    cmd.add(outPref);           // p
    cmd.add(fileName);          // o
    cmd.add(incrType);          // i
    cmd.add(groups);            // g
    cmd.add(verFmt);            // f
    cmd.add(createFile);        // c
    cmd.parse(argc, argv);
    
    /* Fill the static vector here. */
    m_static.fill(nullInitial, 4);
    
    /* Extract the options. */
    m_filePath     = fromStdString(fileName.getValue());
    m_format       = fromStdString(verFmt.getValue());
    m_formatter    = fromStdString(formatter.getValue());
    m_baseYear     = baseYear.getValue();
    m_overflow     = overFlow.getValue();
    m_verbose      = verbose.getValue();
    m_createFile   = createFile.getValue();
    m_groups       = groups.getValue();
    m_outputPrefix = fromStdString(outPref.getValue());

    /* Extract the incrementation type. */
    if (incrType.getValue().compare("date") == 0) {
      m_incrType = BuildByDate;
    } else if (incrType.getValue().compare("months") == 0) {
      m_incrType = BuildByMonths;
    } else if (incrType.getValue().compare("years") == 0) {
      m_incrType = BuildByYears;
    } else {
      m_incrType = BuildSimple;
    }
    
    /* Are we to use stdout? */
    if (m_filePath.isNull() || m_filePath.length() == 0)
    {  
      m_useStdOut = true;
    } else {
      m_useStdOut = false;
    }
  }
  
  catch (TCLAP::ArgException &e) {
    std::cerr << "Error: " << e.error()
              << " for arg " << e.argId()
              << std::endl;
  }
}                               // Settings::Settings()