void tst_QVersitProperty::testParameters()
{
    QString typeParameterName(QLatin1String("TYPE"));

    QString name(QLatin1String("type"));
    QString value1(QLatin1String("home"));
    mVersitProperty->insertParameter(name,value1);
    QMultiHash<QString,QString> parameters = mVersitProperty->parameters();
    QCOMPARE(parameters.count(), 1);
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("home")));

    QString value2(QLatin1String("voice"));
    mVersitProperty->insertParameter(name,value2);
    parameters = mVersitProperty->parameters();
    QCOMPARE(parameters.count(), 2);
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("home")));
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("voice")));

    mVersitProperty->removeParameter(name,value1);
    QCOMPARE(mVersitProperty->parameters().count(), 1);
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("home")));

    mVersitProperty->removeParameter(name,value2);
    QCOMPARE(mVersitProperty->parameters().count(), 0);

    mVersitProperty->insertParameter(name, value1);
    mVersitProperty->insertParameter(name, value2);
    QCOMPARE(mVersitProperty->parameters().count(), 2);
    mVersitProperty->removeParameters(name);
    QCOMPARE(mVersitProperty->parameters().count(), 0);
}
Beispiel #2
0
void mythfile_open_register_callback(const char *pathname, void* object,
                                     callback_t func)
{
    m_callbackLock.lock();
    QString path(pathname);
    if (m_fileOpenCallbacks.contains(path))
    {
        // if we already have a callback registered for this path with this
        // object then remove the callback and return (i.e. end callback)
        QMutableHashIterator<QString,Callback> it(m_fileOpenCallbacks);
        while (it.hasNext())
        {
            it.next();
            if (object == it.value().m_object)
            {
                it.remove();
                VERBOSE(VB_PLAYBACK, LOC +
                    QString("Removing fileopen callback for %1").arg(path));
                VERBOSE(VB_PLAYBACK, LOC + QString("%1 callbacks remaining")
                    .arg(m_fileOpenCallbacks.size()));
                m_callbackLock.unlock();
                return;
            }
        }
    }

    Callback new_callback(object, func);
    m_fileOpenCallbacks.insert(path, new_callback);
    VERBOSE(VB_PLAYBACK, LOC +
        QString("Added fileopen callback for %1").arg(path));
    VERBOSE(VB_PLAYBACK, LOC + QString("%1 callbacks open")
        .arg(m_fileOpenCallbacks.size()));

    m_callbackLock.unlock();
}
Beispiel #3
0
bool LimitedNodeList::packetVersionMatch(const udt::Packet& packet) {
    PacketType headerType = NLPacket::typeInHeader(packet);
    PacketVersion headerVersion = NLPacket::versionInHeader(packet);
    
    if (headerVersion != versionForPacketType(headerType)) {
        
        static QMultiHash<QUuid, PacketType> sourcedVersionDebugSuppressMap;
        static QMultiHash<HifiSockAddr, PacketType> versionDebugSuppressMap;
        
        bool hasBeenOutput = false;
        QString senderString;
        
        if (NON_SOURCED_PACKETS.contains(headerType)) {
            const HifiSockAddr& senderSockAddr = packet.getSenderSockAddr();
            hasBeenOutput = versionDebugSuppressMap.contains(senderSockAddr, headerType);
            
            if (!hasBeenOutput) {
                versionDebugSuppressMap.insert(senderSockAddr, headerType);
                senderString = QString("%1:%2").arg(senderSockAddr.getAddress().toString()).arg(senderSockAddr.getPort());
            }
        } else {
            QUuid sourceID = NLPacket::sourceIDInHeader(packet);
            
            hasBeenOutput = sourcedVersionDebugSuppressMap.contains(sourceID, headerType);
            
            if (!hasBeenOutput) {
                sourcedVersionDebugSuppressMap.insert(sourceID, headerType);
                senderString = uuidStringWithoutCurlyBraces(sourceID.toString());
            }
        }
        
        if (!hasBeenOutput) {
            qCDebug(networking) << "Packet version mismatch on" << headerType << "- Sender"
                << senderString << "sent" << qPrintable(QString::number(headerVersion)) << "but"
                << qPrintable(QString::number(versionForPacketType(headerType))) << "expected.";
            
            emit packetVersionMismatch(headerType);
        }
        
        return false;
    } else {
        return true;
    }
}
void SwitchWindow::makeMenu()
{
    qDeleteAll(m_actions);
    m_actions.clear();

    if (m_tasksModel->rowCount() == 0) {
        return;
    }

    QMultiHash<int, QAction*> desktops;

    //make all the window actions
    for (int i = 0; i < m_tasksModel->rowCount(); ++i) {
        if (m_tasksModel->data(m_tasksModel->index(i, 0), LegacyTaskManager::TasksModel::IsStartup).toBool()) {
            qDebug() << "skipped fake task";
            continue;
        }

        QString name = m_tasksModel->data(m_tasksModel->index(i, 0), Qt::DisplayRole).toString();

        if (name.isEmpty()) {
            continue;
        }

        QAction *action = new QAction(name, this);
        action->setIcon(m_tasksModel->data(m_tasksModel->index(i, 0), Qt::DecorationRole).value<QIcon>());
        action->setData(m_tasksModel->data(m_tasksModel->index(i, 0), LegacyTaskManager::TasksModel::Id).toString());
        desktops.insert(m_tasksModel->data(m_tasksModel->index(i, 0), LegacyTaskManager::TasksModel::Desktop).toInt(), action);
        connect(action, &QAction::triggered, [=]() {
            switchTo(action);
        });
    }

    //sort into menu
    if (m_mode == CurrentDesktop) {
        int currentDesktop = KWindowSystem::currentDesktop();

        QAction *a = new QAction(i18nc("plasma_containmentactions_switchwindow", "Windows"), this);
        a->setSeparator(true);
        m_actions << a;
        m_actions << desktops.values(currentDesktop);
        m_actions << desktops.values(-1);

    } else {
        int numDesktops = KWindowSystem::numberOfDesktops();
        if (m_mode == AllFlat) {
            for (int i = 1; i <= numDesktops; ++i) {
                if (desktops.contains(i)) {
                    QString name = KWindowSystem::desktopName(i);
                    name = QStringLiteral("%1: %2").arg(i).arg(name);
                    QAction *a = new QAction(name, this);
                    a->setSeparator(true);
                    m_actions << a;
                    m_actions << desktops.values(i);
                }
            }
            if (desktops.contains(-1)) {
                QAction *a = new QAction(i18nc("plasma_containmentactions_switchwindow", "All Desktops"), this);
                a->setSeparator(true);
                m_actions << a;
                m_actions << desktops.values(-1);
            }

        } else { //submenus
            for (int i = 1; i <= numDesktops; ++i) {
                if (desktops.contains(i)) {
                    QString name = KWindowSystem::desktopName(i);
                    name = QStringLiteral("%1: %2").arg(i).arg(name);
                    QMenu *subMenu = new QMenu(name);
                    subMenu->addActions(desktops.values(i));

                    QAction *a = new QAction(name, this);
                    a->setMenu(subMenu);
                    m_actions << a;
                }
            }
            if (desktops.contains(-1)) {
                QMenu *subMenu = new QMenu(i18nc("plasma_containmentactions_switchwindow", "All Desktops"));
                subMenu->addActions(desktops.values(-1));
                QAction *a = new QAction(i18nc("plasma_containmentactions_switchwindow", "All Desktops"), this);
                a->setMenu(subMenu);
                m_actions << a;
            }
        }
    }
}
Beispiel #5
0
int main(int argc, char **argv)
{
  QxtCommandOptions options;

  options.add(CL_HELP, "display this help message",
      QxtCommandOptions::NoValue);
  options.add(CL_NKEYS, "number of keys to generate",
      QxtCommandOptions::ValueRequired);
  options.add(CL_PUBDIR, "directory in which to put public keys (default=./keys/pub)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_PRIVDIR, "directory in which to put private keys (default=./keys/priv)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_KEYTYPE, "specify the key type (default=dsa, options=dsa|rsa)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_LIB, "specify the library (default=cryptopp, options=cryptopp)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_RAND, "specify the base properties for the key (default=NULL)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_DEBUG, "enable debugging",
      QxtCommandOptions::NoValue);

  options.parse(argc, argv);

  if(options.count(CL_HELP) || options.showUnrecognizedWarning()) {
    options.showUsage();
    return -1;
  }

  QMultiHash<QString, QVariant> params = options.parameters();

  int key_count = params.value(CL_NKEYS, 1).toInt();
  if(key_count < 1) {
    ExitWithWarning(options, "Invalid nkeys");
  }

  QString pubdir_path = params.value(CL_PUBDIR, DEFAULT_PUBDIR).toString();
  QDir pubdir(pubdir_path);
  if(!pubdir.exists()) {
    pubdir.mkpath(".");
  }

  if(!pubdir.exists()) {
    ExitWithWarning(options, "Unable to create pubdir");
  }

  QString privdir_path = params.value(CL_PRIVDIR, DEFAULT_PRIVDIR).toString();
  QDir privdir(privdir_path);
  if(!privdir.exists()) {
    privdir.mkpath(".");
  }

  if(!privdir.exists()) {
    ExitWithWarning(options, "Unable to create privdir");
  }

  if(params.contains(CL_DEBUG)) {
    Logging::UseStderr();
  }

  QString lib_name = params.value(CL_LIB, "cryptopp").toString();
  QString key = params.value(CL_KEYTYPE, "dsa").toString();

  CryptoFactory &cf = CryptoFactory::GetInstance();
  QSharedPointer<CreateKey> ck(new CreateKey());
  if(lib_name == "cryptopp") {
    if(key == "dsa") {
      cf.SetLibrary(CryptoFactory::CryptoPPDsa);
      if(params.contains(CL_RAND)) {
        ck = QSharedPointer<CreateKey>(
            new CreateSeededDsaKey(params.value(CL_RAND).toString()));
      }
    } else if (key == "rsa") {
      cf.SetLibrary(CryptoFactory::CryptoPP);
    } else {
      ExitWithWarning(options, "Invalid key type");
    }
  } else {
    ExitWithWarning(options, "Invalid library");
  }

  Library *lib = cf.GetLibrary();
  QSharedPointer<Hash> hash(lib->GetHashAlgorithm());

  int count = 0;
  while(count < key_count) {
    QSharedPointer<AsymmetricKey> key((*ck)());
    QSharedPointer<AsymmetricKey> pubkey(key->GetPublicKey());
    QByteArray hvalue = hash->ComputeHash(pubkey->GetByteArray());
    QString id = Integer(hvalue).ToString();

    if(!key->Save(privdir_path + QDir::separator() + id)) {
      qFatal("Could not save private key");
    }

    if(!pubkey->Save(pubdir_path + QDir::separator() + id + ".pub")) {
      qFatal("Could not save private key");
    }

    count++;
  }

  return 0;
}
Beispiel #6
0
void SwitchWindow::makeMenu()
{
    m_menu->clear();
    Plasma::DataEngine *tasks = dataEngine("tasks");
    if (!tasks->isValid()) {
        return;
    }

    QMultiHash<int, QAction*> desktops;

    //make all the window actions
    foreach (const QString &source, tasks->sources()) {
        Plasma::DataEngine::Data window = tasks->query(source);
        if (window.value("startup").toBool()) {
            //kDebug() << "skipped fake task" << source;
            continue;
        }
        if (!window.value("onCurrentActivity").toBool()) {
            continue;
        }

        QString name = window.value("visibleNameWithState").toString();
        if (name.isEmpty()) {
            kDebug() << "failed source" << source;
            continue;
        }

        QAction *action = new QAction(name, m_menu);
        action->setIcon(window.value("icon").value<QIcon>());
        action->setData(source);
        desktops.insert(window.value("desktop").toInt(), action);
    }

    //sort into menu
    if (m_mode == CurrentDesktop) {
        int currentDesktop = KWindowSystem::currentDesktop();
        m_menu->addTitle(i18n("Windows"));
        m_menu->addActions(desktops.values(currentDesktop));
        m_menu->addActions(desktops.values(-1));
    } else {
        int numDesktops = KWindowSystem::numberOfDesktops();
        if (m_mode == AllFlat) {
            for (int i = 1; i <= numDesktops; ++i) {
                if (desktops.contains(i)) {
                    QString name = KWindowSystem::desktopName(i);
                    name = QString("%1: %2").arg(i).arg(name);
                    m_menu->addTitle(name);
                    m_menu->addActions(desktops.values(i));
                }
            }
            if (desktops.contains(-1)) {
                m_menu->addTitle(i18n("All Desktops"));
                m_menu->addActions(desktops.values(-1));
            }
        } else { //submenus
            for (int i = 1; i <= numDesktops; ++i) {
                if (desktops.contains(i)) {
                        QString name = KWindowSystem::desktopName(i);
                        name = QString("%1: %2").arg(i).arg(name);
                        KMenu *subMenu = new KMenu(name, m_menu);
                        subMenu->addActions(desktops.values(i));
                        m_menu->addMenu(subMenu);
                }
            }
            if (desktops.contains(-1)) {
                KMenu *subMenu = new KMenu(i18n("All Desktops"), m_menu);
                subMenu->addActions(desktops.values(-1));
                m_menu->addMenu(subMenu);
            }
        }
    }

    m_menu->adjustSize();
}
QList<CellItem*> CellItem::placeItem( QList<CellItem*> cells, CellItem *placeItem )
{
  kDebug(5855) << "Placing" << placeItem->label();

  QList<KOrg::CellItem*> conflictItems;
  int maxSubCells = 0;
  QMultiHash<int,KOrg::CellItem*> subCellDict;

  // Find all items which are in same cell
  QList<KOrg::CellItem*>::iterator it;
  for ( it = cells.begin(); it != cells.end(); ++it ) {
    KOrg::CellItem *item = *it;
    if ( item == placeItem ) {
      continue;
    }

    if ( item->overlaps( placeItem ) ) {
      kDebug(5855) << "  Overlaps:" << item->label();

      conflictItems.append( item );
      if ( item->subCells() > maxSubCells ) {
        maxSubCells = item->subCells();
      }
      subCellDict.insert( item->subCell(), item );
    }
  }

  if ( !conflictItems.empty() ) {
    // Look for unused sub cell and insert item
    int i;
    for ( i = 0; i < maxSubCells; ++i ) {
      kDebug(5855) << "  Trying subcell" << i;
      if ( !subCellDict.contains( i ) ) {
        kDebug(5855) << "  Use subcell" << i;
        placeItem->setSubCell( i );
        break;
      }
    }
    if ( i == maxSubCells ) {
      kDebug(5855) << "  New subcell" << i;
      placeItem->setSubCell( maxSubCells );
      maxSubCells++;  // add new item to number of sub cells
    }

    kDebug(5855) << "  Sub cells:" << maxSubCells;

    // Write results to item to be placed
    conflictItems.append( placeItem );
    placeItem->setSubCells( maxSubCells );

    QList<KOrg::CellItem*>::iterator it;
    for ( it = conflictItems.begin(); it != conflictItems.end(); ++it ) {
      (*it)->setSubCells( maxSubCells );
    }
    // Todo: Adapt subCells of items conflicting with conflicting items
  } else {
    kDebug(5855) << "  no conflicts";
    placeItem->setSubCell( 0 );
    placeItem->setSubCells( 1 );
  }

  return conflictItems;
}