/*! * \brief The OfflineMessageManager::offlineMessageManagerReply method parse an offline message query an return response * \param iqXML * \param iqFrom * \return QByteArray */ QByteArray OfflineMessageManager::offlineMessageManagerReply(QDomDocument document, QString iqFrom) { QString id = document.documentElement().attribute("id", Utils::generateId()); QString offlineFirstChildTagName = document.documentElement().firstChildElement().firstChildElement().tagName(); if (offlineFirstChildTagName == "fetch") { QMultiHash<QString, QByteArray> messageList = getAllOfflineMessage(Utils::getBareJid(iqFrom)); QList<QString> keyList = messageList.keys(); QByteArray allMessages; foreach (QString key, keyList) { QDomDocument document; document.setContent(messageList.value(key)); QDomElement offlineElement = document.createElement("offline"); offlineElement.setAttribute("xmlns", "http://jabber.org/protocol/offline"); QDomElement item = document.createElement("item"); item.setAttribute("node", key); offlineElement.appendChild(item); document.documentElement().appendChild(offlineElement); allMessages += document.toByteArray(); }
bool QVCardRestoreHandler::propertyProcessed( const QVersitProperty& property, QList<QContactDetail>* updatedDetails) { bool success = false; QString group; if (!property.groups().isEmpty()) group = property.groups().first(); if (property.name() == PropertyName) { if (property.groups().size() != 1) return false; QMultiHash<QString, QString> parameters = property.parameters(); QContactDetail::DetailType detailType = QContactDetail::DetailType(parameters.value(DetailTypeParameter).toUInt()); QString fieldName = parameters.value(FieldParameter); // Find a detail previously seen with the same definitionName, which was generated from // a property from the same group QContactDetail detail(detailType); foreach (const QContactDetail& previousDetail, mDetailGroupMap.detailsInGroup(group)) { if (previousDetail.type() == detailType) { detail = previousDetail; } } // If not found, it's a new empty detail with the definitionName set. detail.setValue(fieldName.toInt(), deserializeValue(property)); // Replace the equivalent detail in updatedDetails with the new one QMutableListIterator<QContactDetail> it(*updatedDetails); while (it.hasNext()) { if (it.next().key() == detail.key()) { it.remove(); break; } } updatedDetails->append(detail); success = true; } if (!group.isEmpty()) { // Keep track of which details were generated from which Versit groups foreach (const QContactDetail& detail, *updatedDetails) { mDetailGroupMap.insert(group, detail); } }
void DayViewModel::assignDisplayValues() { int count = itemsList.count(); if(count == 0) return; QMultiHash<int,int> hashmap; //Counting how many items start at an index for(int i=0;i<count;i++) { int index = 0,itemCount=0; CalendarDataItem *calItem = ((CalendarDataItem*)(itemsList.at(i))); index = computeStartIndex(calItem->startTime); ((CalendarDataItem*)(itemsList.at(i)))->startIndex = index; ((CalendarDataItem*)(itemsList.at(i)))->xUnits = 0; ((CalendarDataItem*)(itemsList.at(i)))->yUnits = 0; ((CalendarDataItem*)(itemsList.at(i)))->widthUnits = 1.0; double htVal = (calItem->startTime.secsTo(calItem->endTime) / (60.0*30.0)); if(htVal<0.5) { htVal = 0.5; } htVal = round(htVal); ((CalendarDataItem*)(itemsList.at(i)))->heightUnits = htVal; qDebug()<<"xUnits="<<calItem->xUnits<<",yUnits="<<calItem->yUnits<<",widthUnits="<<calItem->widthUnits<<", heightUnits="<<calItem->heightUnits<<",startIndex="<<calItem->startIndex; for(int j=0;j<calItem->heightUnits;j++) { if(hashmap.count(index+j) == 0) { itemCount = 1; } else { itemCount = hashmap.value(index+j); itemCount++; } hashmap.replace(index+j,itemCount); } } //Assign width values based on number of items at an index and their height for(int i=0;i<count;i++) { CalendarDataItem *calItem = ((CalendarDataItem*)(itemsList.at(i))); int startIndex = calItem->startIndex; int htUnits = calItem->heightUnits; int maxCount=1,tmpVal=0; for(int j=0;j<htUnits;j++) { tmpVal = hashmap.value(startIndex+j); if(tmpVal>maxCount) { maxCount = tmpVal; } } calItem->widthUnits = (calItem->widthUnits)/maxCount; } //Assign xUnits value QMultiHash<int,int> xOffsetHashmap; for(int i=0;i<count;i++) { int itemCount=0; CalendarDataItem *calItem = ((CalendarDataItem*)(itemsList.at(i))); int startIndex = calItem->startIndex; int htUnits = calItem->heightUnits; int maxCount=0,tmpVal=0; for(int j=0;j<htUnits;j++) { tmpVal = xOffsetHashmap.value(startIndex+j); if(tmpVal>maxCount) { maxCount = tmpVal; } } calItem->xUnits=maxCount; for(int j=0;j<htUnits;j++) { if(xOffsetHashmap.count(startIndex+j) == 0) { itemCount = 1; } else { itemCount = xOffsetHashmap.value(startIndex+j); itemCount++; } xOffsetHashmap.replace(startIndex+j,itemCount); } } return; }
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; }
QString timetrackerstorage::load(TaskView* view, const QString &fileName) // loads data from filename into view. If no filename is given, filename from preferences is used. // filename might be of use if this program is run as embedded konqueror plugin. { Q_UNUSED(fileName); // TODO: receive changes from akonadi kDebug(5970) << "Entering function"; QString err; KEMailSettings settings; // If file doesn't exist, create a blank one to avoid ResourceLocal load // error. We make it user and group read/write, others read. This is // masked by the users umask. (See man creat) if ( d->mCalendar ) closeStorage(); // Create local file resource and add to resources d->mICalFile = ""; d->mCalendar = KTTCalendar::createInstance(); QObject::connect( d->mCalendar.data(), SIGNAL(calendarChanged()), view, SLOT(iCalFileModified()) ); d->mCalendar->setTimeSpec( KSystemTimeZones::local() ); d->mCalendar->reload(); // Claim ownership of iCalendar file if no one else has. KCalCore::Person::Ptr owner = d->mCalendar->owner(); if ( owner && owner->isEmpty() ) { // TODO d->mCalendar->setOwner( KCalCore::Person::Ptr( new KCalCore::Person( settings.getSetting( KEMailSettings::RealName ), settings.getSetting( KEMailSettings::EmailAddress ) ) ) ); } // TODO // Build task view from iCal data if (!err.isEmpty()) { KCalCore::Todo::List todoList; KCalCore::Todo::List::ConstIterator todo; QMultiHash< QString, Task* > map; // Build dictionary to look up Task object from Todo uid. Each task is a // QListViewItem, and is initially added with the view as the parent. todoList = d->mCalendar->rawTodos(); kDebug(5970) << "timetrackerstorage::load" << "rawTodo count (includes completed todos) =" << todoList.count(); for (todo = todoList.constBegin(); todo != todoList.constEnd(); ++todo) { Task* task = new Task(*todo, view); map.insert( (*todo)->uid(), task ); view->setRootIsDecorated(true); task->setPixmapProgress(); } // Load each task under it's parent task. for (todo = todoList.constBegin(); todo != todoList.constEnd(); ++todo) { Task* task = map.value( (*todo)->uid() ); // No relatedTo incident just means this is a top-level task. if ( !(*todo)->relatedTo().isEmpty() ) { Task *newParent = map.value( (*todo)->relatedTo() ); // Complete the loading but return a message if ( !newParent ) err = i18n("Error loading \"%1\": could not find parent (uid=%2)", task->name(), (*todo)->relatedTo() ); if (!err.isEmpty()) task->move( newParent ); } } kDebug(5970) << "timetrackerstorage::load - loaded" << view->count() << "tasks from" << d->mICalFile; } if ( view ) buildTaskView(d->mCalendar->weakPointer(), view); this->save(view); // FIXME ? return err; }
QString timetrackerstorage::buildTaskView( const KTimeTracker::KTTCalendar::Ptr &calendar, TaskView *view ) // makes *view contain the tasks out of *rc. { kDebug(5970) << "Entering function"; QString err; KCalCore::Todo::List todoList; KCalCore::Todo::List::ConstIterator todo; QMultiHash< QString, Task* > map; QVector<QString> runningTasks; QVector<QDateTime> startTimes; // remember tasks that are running and their start times QTreeWidgetItemIterator it( view ); while ( *it ) { Task *task = static_cast< Task* >( *it ); if ( task->isRunning() ) { runningTasks.append( task->uid() ); startTimes.append( task->startTime() ); } ++it; } view->clear(); todoList = calendar->rawTodos(); for ( todo = todoList.constBegin(); todo != todoList.constEnd(); ++todo ) { Task* task = new Task(*todo, view); task->setWhatsThis(0,i18n("The task name is what you call the task, it can be chosen freely.")); task->setWhatsThis(1,i18n("The session time is the time since you last chose \"start new session.\"")); map.insert( (*todo)->uid(), task ); view->setRootIsDecorated(true); task->setPixmapProgress(); } // 1.1. Load each task under it's parent task. for( todo = todoList.constBegin(); todo != todoList.constEnd(); ++todo ) { Task* task = map.value( (*todo)->uid() ); // No relatedTo incident just means this is a top-level task. if ( !(*todo)->relatedTo().isEmpty() ) { Task* newParent = map.value( (*todo)->relatedTo() ); // Complete the loading but return a message if ( !newParent ) err = i18n("Error loading \"%1\": could not find parent (uid=%2)", task->name(), (*todo)->relatedTo()); else task->move( newParent ); } } view->clearActiveTasks(); // restart tasks that have been running with their start times for ( int i=0; i<view->count(); i++) { for ( int n = 0; n < runningTasks.count(); ++n ) { if ( runningTasks[n] == view->itemAt(i)->uid() ) { view->startTimerFor( view->itemAt(i), startTimes[n] ); } } } view->refresh(); return err; }
/*! * Handles incoming HTTP requests and dispatches them to the appropriate service. * * The \a requestID is an opaque value generated by the connector. * * Subclasses may override this function to perform preprocessing on each * request, but they must call the base class implementation in order to * generate and dispatch the appropriate events. * * To facilitate use with multi-threaded applications, the event will remain * valid until a response is posted. */ void QxtHttpSessionManager::incomingRequest(quint32 requestID, const QHttpRequestHeader& header, QxtWebContent* content) { QMultiHash<QString, QString> cookies; foreach(const QString& cookie, header.allValues("cookie")) // QHttpHeader is case-insensitive, thankfully { foreach(const QString& kv, cookie.split("; ")) { int pos = kv.indexOf('='); if (pos == -1) continue; cookies.insert(kv.left(pos), kv.mid(pos + 1)); } } int sessionID; QString sessionCookie = cookies.value(qxt_d().sessionCookieName); qxt_d().sessionLock.lock(); if (qxt_d().sessionKeys.contains(sessionCookie)) { sessionID = qxt_d().sessionKeys[sessionCookie]; if(!sessionID && header.majorVersion() > 0 && qxt_d().autoCreateSession) sessionID = newSession(); } else if (header.majorVersion() > 0 && qxt_d().autoCreateSession) { sessionID = newSession(); } else { sessionID = 0; } QIODevice* device = connector()->getRequestConnection(requestID); QxtHttpSessionManagerPrivate::ConnectionState& state = qxt_d().connectionState[device]; state.sessionID = sessionID; state.httpMajorVersion = header.majorVersion(); state.httpMinorVersion = header.minorVersion(); if (state.httpMajorVersion == 0 || (state.httpMajorVersion == 1 && state.httpMinorVersion == 0) || header.value("connection").toLower() == "close") state.keepAlive = false; else state.keepAlive = true; qxt_d().sessionLock.unlock(); QxtWebRequestEvent* event = new QxtWebRequestEvent(sessionID, requestID, QUrl::fromEncoded(header.path().toUtf8())); qxt_d().eventLock.lock(); qxt_d().pendingRequests.insert(QPair<int,int>(sessionID, requestID), event); qxt_d().eventLock.unlock(); QTcpSocket* socket = qobject_cast<QTcpSocket*>(device); if (socket) { event->remoteAddress = socket->peerAddress(); #if defined(QT_SECURETRANSPORT) || !defined(QT_NO_OPENSSL) QSslSocket* sslSocket = qobject_cast<QSslSocket*>(socket); if(sslSocket) { event->isSecure = true; event->clientCertificate = sslSocket->peerCertificate(); } #endif } event->method = header.method(); event->cookies = cookies; event->url.setScheme("http"); if (event->url.host().isEmpty()) event->url.setHost(header.value("host")); if (event->url.port() == -1) event->url.setPort(port()); event->contentType = header.contentType(); event->content = content; typedef QPair<QString, QString> StringPair; foreach(const StringPair& line, header.values()) { if (line.first.toLower() == "cookie") continue; event->headers.insert(line.first, line.second); } event->headers.insert("X-Request-Protocol", "HTTP/" + QString::number(state.httpMajorVersion) + '.' + QString::number(state.httpMinorVersion)); if (sessionID && session(sessionID)) { QxtAbstractWebService *service = session(sessionID); if(content) content->setParent(service); // Set content ownership to the service service->pageRequestedEvent(event); } else if (qxt_d().staticService) { qxt_d().staticService->pageRequestedEvent(event); } else { postEvent(new QxtWebErrorEvent(0, requestID, 500, "Internal Configuration Error")); } }
namespace EdictFormatting { // Forward declarations of our functions to be used. QMultiHash<QString, QString> createPartOfSpeechCategories(); QSet<QString> createPartsOfSpeech(); QSet<QString> createMiscMarkings(); QSet<QString> createFieldOfApplication(); QStringList createNounsList(); QStringList createVerbsList(); QStringList createExpressionsList(); QStringList createPrefixesList(); QStringList createSuffixesList(); // Private variables. QString noun = QString( i18nc( "This must be a single word", "Noun" ) ); QString verb = QString( i18nc( "This must be a single word", "Verb" ) ); QString adjective = QString( i18nc( "This must be a single word", "Adjective" ) ); QString adverb = QString( i18nc( "This must be a single word", "Adverb" ) ); QString particle = QString( i18nc( "This must be a single word", "Particle" ) ); QString ichidanVerb = QString( i18nc( "This is a technical japanese linguist's term... and probably should not be translated (except possibly in far-eastern languages), this must be a single word", "Ichidan" ) ); QString godanVerb = QString( i18nc( "This is a technical japanese linguist's term... and probably should not be translated, this must be a single word", "Godan" ) ); QString fukisokuVerb = QString( i18nc( "This is a technical japanese linguist's term... and probably should not be translated, this must be a single word", "Fukisoku" ) ); QString expression = QString( i18n( "Expression" ) ); QString idiomaticExpression = QString( i18n( "Idiomatic expression" ) ); QString prefix = QString( i18n( "Prefix" ) ); QString suffix = QString( i18n( "Suffix" ) ); QString nounPrefix = QString( i18n( "Noun (used as a prefix)" ) ); QString nounSuffix = QString( i18n( "Noun (used as a suffix)" ) ); // Define our public variables. QMultiHash<QString, QString> PartOfSpeechCategories = createPartOfSpeechCategories(); QSet<QString> PartsOfSpeech = createPartsOfSpeech(); QSet<QString> MiscMarkings = createMiscMarkings(); QSet<QString> FieldOfApplication = createFieldOfApplication(); // PartOfSpeechCategories needs to has some values before this line. QStringList Nouns = createNounsList(); QStringList Adjectives = PartOfSpeechCategories.values( adjective ); QStringList Adverbs = PartOfSpeechCategories.values( adverb ); QStringList IchidanVerbs = PartOfSpeechCategories.values( ichidanVerb ); QStringList GodanVerbs = PartOfSpeechCategories.values( godanVerb ); QStringList FukisokuVerbs = PartOfSpeechCategories.values( fukisokuVerb ); QStringList Verbs = createVerbsList(); QStringList Expressions = createExpressionsList(); QStringList Prefix = createPrefixesList(); QStringList Suffix = createSuffixesList(); QString Particle = PartOfSpeechCategories.value( particle ); QStringList createNounsList() { QStringList list; list.append( PartOfSpeechCategories.values( noun ) ); list.append( PartOfSpeechCategories.values( nounPrefix ) ); list.append( PartOfSpeechCategories.values( nounSuffix ) ); return list; } QStringList createVerbsList() { QStringList list; list.append( PartOfSpeechCategories.values( verb ) ); list.append( IchidanVerbs ); list.append( GodanVerbs ); list.append( FukisokuVerbs ); return list; } QStringList createExpressionsList() { QStringList list; list.append( PartOfSpeechCategories.values( expression ) ); list.append( PartOfSpeechCategories.values( idiomaticExpression ) ); return list; } QStringList createPrefixesList() { QStringList list; list.append( PartOfSpeechCategories.values( prefix ) ); list.append( PartOfSpeechCategories.values( nounPrefix ) ); return list; } QStringList createSuffixesList() { QStringList list; list.append( PartOfSpeechCategories.values( suffix ) ); list.append( PartOfSpeechCategories.values( nounSuffix ) ); return list; } QMultiHash<QString, QString> createPartOfSpeechCategories() { QMultiHash<QString, QString> categories; // Nouns categories.insert( noun, "n" ); categories.insert( noun, "n-adv" ); categories.insert( noun, "n-t" ); categories.insert( noun, "adv-n" ); // Noun (used as a prefix) categories.insert( nounPrefix, "n-pref" ); // Noun (used as a suffix) categories.insert( nounSuffix, "n-suf" ); // Ichidan Verbs categories.insert( ichidanVerb, "v1" ); categories.insert( ichidanVerb, "vz" ); // Godan Verbs categories.insert( godanVerb, "v5" ); categories.insert( godanVerb, "v5aru" ); categories.insert( godanVerb, "v5b" ); categories.insert( godanVerb, "v5g" ); categories.insert( godanVerb, "v5k" ); categories.insert( godanVerb, "v5k-s" ); categories.insert( godanVerb, "v5m" ); categories.insert( godanVerb, "v5n" ); categories.insert( godanVerb, "v5r" ); categories.insert( godanVerb, "v5r-i" ); categories.insert( godanVerb, "v5s" ); categories.insert( godanVerb, "v5t" ); categories.insert( godanVerb, "v5u" ); categories.insert( godanVerb, "v5u-s" ); categories.insert( godanVerb, "v5uru" ); categories.insert( godanVerb, "v5z" ); // Fukisoku verbs categories.insert( fukisokuVerb, "iv" ); categories.insert( fukisokuVerb, "vk" ); categories.insert( fukisokuVerb, "vn" ); categories.insert( fukisokuVerb, "vs-i" ); categories.insert( fukisokuVerb, "vs-s" ); // Other Verbs categories.insert( verb, "vi" ); categories.insert( verb, "vs" ); categories.insert( verb, "vt" ); categories.insert( verb, "aux-v" ); // Adjectives categories.insert( adjective, "adj-i" ); categories.insert( adjective, "adj-na" ); categories.insert( adjective, "adj-no" ); categories.insert( adjective, "adj-pn" ); categories.insert( adjective, "adj-t" ); categories.insert( adjective, "adj-f" ); categories.insert( adjective, "adj" ); categories.insert( adjective, "aux-adj" ); // Adverbs categories.insert( adverb, "adv" ); categories.insert( adverb, "adv-n" ); categories.insert( adverb, "adv-to" ); // Particle categories.insert( particle, "prt" ); // Expression categories.insert( expression, "exp" ); // Idiomatic expression categories.insert( idiomaticExpression, "id" ); // Prefix categories.insert( prefix, "pref" ); // Suffix categories.insert( suffix, "suf" ); return categories; } QSet<QString> createPartsOfSpeech() { QSet<QString> category; category << "adj-i" << "adj-na" << "adj-no" << "adj-pn" << "adj-t" << "adj-f" << "adj" << "adv" << "adv-n" << "adv-to" << "aux" << "aux-v" << "aux-adj" << "conj" << "ctr" << "exp" << "id" << "int" << "iv" << "n" << "n-adv" << "n-pref" << "n-suf" << "n-t" << "num" << "pn" << "pref" << "prt" << "suf" << "v1" << "v5" << "v5aru" << "v5b" << "v5g" << "v5k" << "v5k-s" << "v5m" << "v5n" << "v5r" << "v5r-i" << "v5s" << "v5t" << "v5u" << "v5u-s" << "v5uru" << "v5z" << "vz" << "vi" << "vk" << "vn" << "vs" << "vs-i" << "vs-s" << "vt"; return category; } QSet<QString> createFieldOfApplication() { QSet<QString> category; // Field of Application terms category << "Buddh" << "MA" << "comp" << "food" << "geom" << "ling" << "math" << "mil" << "physics"; return category; } QSet<QString> createMiscMarkings() { QSet<QString> category; // Miscellaneous Markings (in EDICT terms) category << "X" << "abbr" << "arch" << "ateji" << "chn" << "col" << "derog" << "eK" << "ek" << "fam" << "fem" << "gikun" << "hon" << "hum" << "iK" << "id" << "io" << "m-sl" << "male" << "male-sl" << "ng" << "oK" << "obs" << "obsc" << "ok" << "poet" << "pol" << "rare" << "sens" << "sl" << "uK" << "uk" << "vulg"; return category; } }