QIntDict<QString> EventItem::actions() { QIntDict<QString> result; result.insert( 0, new QString( QObject::tr("show") ) ); result.insert( 1, new QString( QObject::tr("edit") ) ); return result; }
void GadWorkspace::load(const ClassDict & classDict, const QString & filename) { qDebug("GadWorkspace::load\n"); classDict_ = &classDict; genMenu(); QFile fp(filename); if (!fp.open(IO_ReadOnly)) return; MLParser parser(&fp); QString keywords[] = { "OBJECT", "" }; MLTagTable tagtable(keywords); int tag; QIntDict < GadObject > dict; while ((tag = parser.tag(tagtable)) != MLParser::END_OF_FILE) { GadObject *obj; qDebug("tag=%d\n", tag); switch (tag) { case 1: obj = new GadObject(classDict, parser.args(), this); dict.insert(obj->id(), obj); break; default: delete parser.args(); } } qDebug("GadWorkspace::load: connecting\n"); QIntDictIterator < GadObject > it(dict); for (; it.current(); ++it) { it.current()->connectObject(dict); } resize(); qDebug("GadWorkspace::load: connecting done\n"); }
QIntDict<QString>* ConfigHelper::stringList2intDict(QStringList stringList) { QIntDict<QString>* filterDict = new QIntDict<QString>; // loop over all entries in the stringlist for (QStringList::Iterator it = stringList.begin(); it != stringList.end(); ++it) { tracer->sdebug(__func__) << "Handling entry: '" << *it << "'" << endl; // split the current entry into key and value and put them into the intdict int delimitorPos = (*it).find(':'); if (delimitorPos > 0) { QString keyStr = (*it).mid(0, delimitorPos); QString value = (*it).mid(delimitorPos + 1); tracer->sdebug(__func__) << "key-->value: '" << keyStr << "-->" << value << "'" << endl; bool ok; int key = keyStr.toInt(&ok); if (ok) { filterDict->insert(key, new QString(value)); } else { tracer->swarning(__func__) << "Key '" << *it << "' is invalid! It is not a number. (Valid format: 'key:value')" << endl; } } else { tracer->swarning(__func__) << "KeyValue pair '" << *it << "' is invalid! (Valid format: 'key:value')" << endl; } } return filterDict; }
void KeyMappings::clear() { for(QMap<int, CodeMaps*>::Iterator it = m_keymaps.begin(); it!=m_keymaps.end(); ++it){ delete (*it); } m_keymaps.clear(); g_mapCache.setAutoDelete(true); g_mapCache.clear(); }
void TEDemo::addSession(TESession* s) { session_no += 1; no2session.insert(session_no,s); session2no.insert(s,(void*)session_no); m_sessions->insertItem(s->Title(), session_no); }
void MainWindow::setCurrent(QListViewItem *item) { if (!item) return; _currentItem = (OListViewItem*)item; // _currentItem = dynamic_cast<OListViewItem*>(item); if (_currentItem->rtti() == OListViewItem::Result) { ResultItem *res = (ResultItem*)item; // ResultItem *res = dynamic_cast<ResultItem*>(item); richEdit->setText( res->toRichText() ); QIntDict<QString> acts = res->actions(); QButton *button; for (uint i = 0; i < acts.count(); i++) { button = buttonMap[i]; if (!button && acts[i]) { owarn << " no button for " << *acts[i] << oendl; button = new QPushButton( buttonBox ); buttonMap.insert( i, button ); signalMapper->setMapping(button, i ); connect(button, SIGNAL(clicked() ), signalMapper, SLOT(map() ) ); } else if (!acts[i]) { owarn << "No action for index " << i << oendl; continue; } button->setText( *acts[i] ); button->show(); } for (uint i = acts.count(); i < _buttonCount; i++) { button = buttonMap[i]; if (button) button->hide(); } _buttonCount = acts.count(); detailsFrame->show(); buttonBox->show(); } else { detailsFrame->hide(); buttonBox->hide(); } popupTimer->start( 300, true ); }
bool Server::setKeyboardLayout( const QString &kb ) { //quick demo version that can be extended QIntDict<QWSServer::KeyMap> *om = 0; if ( kb == "us101" ) { // No tr om = 0; } else if ( kb == "jp109" ) { om = new QIntDict<QWSServer::KeyMap>(37); const KeyOverride *k = jp109keys; while ( k->scan_code ) { om->insert( k->scan_code, &k->map ); k++; } } QWSServer::setOverrideKeys( om ); return TRUE; }
void KWDocStructRootItem::setupArrangement() { deleteAllChildren(); QIntDict<KWDocStructParagItem> parags; parags.setAutoDelete( false ); KWFrameSet* frameset = 0L; KWTextParag* parag = 0L; KoTextDocument* textdoc = 0L; KWDocument* dok = doc(); KWDocStructTextFrameSetItem *item = 0L; QString _name; for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) { frameset = dok->frameSet( i ); if ( frameset->type() == FT_TEXT && frameset->frameSetInfo() == KWFrameSet::FI_BODY && !frameset->groupmanager() && frameset->frameCount()>0) { KWTextFrameSet *tmpParag = dynamic_cast<KWTextFrameSet*> (frameset) ; item = new KWDocStructTextFrameSetItem( this, frameset->name(), tmpParag); textdoc= tmpParag->textDocument(); parag = static_cast<KWTextParag *>(textdoc->firstParag()); while ( parag ) { KoParagCounter *tmpCounter = parag->counter(); if (tmpCounter !=0 && (tmpCounter->style() != KoParagCounter::STYLE_NONE) && (tmpCounter->numbering() == KoParagCounter::NUM_CHAPTER) ) { int _depth = tmpCounter->depth(); if ( _depth == 0 ) { if ( item->childCount() == 0 ) parags.replace( _depth, new KWDocStructParagItem( item,QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ),parag) ); else parags.replace( _depth, new KWDocStructParagItem( item, parags[ _depth ],QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ),parag) ); } else { if (parags[ _depth - 1 ]==0) parags.replace( _depth, new KWDocStructParagItem( item,QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) ); else if ( parags[ _depth - 1 ]->childCount() == 0 ) parags.replace( _depth, new KWDocStructParagItem( parags[ _depth - 1 ],QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) ); else parags.replace( _depth, new KWDocStructParagItem( parags[ _depth - 1 ], parags[ _depth ],QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) ); } } parag = static_cast<KWTextParag *>(parag->next()); } } } if ( childCount() == 0 ) ( void )new KListViewItem( this, i18n( "Empty" ) ); }
void PukeController::insertPObject(int fd, int iWinId, WidgetS *obj){ // If no widget list exists for this fd, create one if(WidgetList[fd] == NULL){ QIntDict<WidgetS> *qidWS = new QIntDict<WidgetS>; qidWS->setAutoDelete(TRUE); WidgetList.insert(fd, qidWS); } // Set main widget structure list WidgetList[fd]->insert(iWinId, obj); // Set reverse list used durring delete to remove the widget widgetId *pwi = new widgetId; pwi->fd = fd; pwi->iWinId = iWinId; char key[keySize]; memset(key, 0, keySize); sprintf(key, "%p", obj->pwidget); revWidgetList.insert(key, pwi); // Now connect to the destroyed signal so we can remove the object from the lists // Once it is deleted connect(obj->pwidget, SIGNAL(destroyed()), this, SLOT(pobjectDestroyed())); }
void Scribble::slotSave() { QPopupMenu *menu = new QPopupMenu( 0 ); QIntDict<QString> formats; formats.setAutoDelete( TRUE ); for ( unsigned int i = 0; i < QImageIO::outputFormats().count(); i++ ) { QString str = QString( QImageIO::outputFormats().at( i ) ); formats.insert( menu->insertItem( QString( "%1..." ).arg( str ) ), new QString( str ) ); } menu->setMouseTracking( TRUE ); int id = menu->exec( bSave->mapToGlobal( QPoint( 0, bSave->height() + 1 ) ) ); if ( id != -1 ) { QString format = *formats[ id ]; QString filename = QFileDialog::getSaveFileName( QString::null, QString( "*.%1" ).arg( format.lower() ), this ); if ( !filename.isEmpty() ) canvas->save( filename, format ); } delete menu; }
static void delete_recursive(QListViewItem *item, const QIntDict< QListViewItem > &new_items) { if(!item) return; QListViewItemIterator it(item); while(it.current()) { if(!new_items.find(it.current()->text(1).toUInt())) { delete_recursive(it.current()->firstChild(), new_items); delete it.current(); } ++it; } }
void TEDemo::addSessionCommand(const char* path) { KSimpleConfig* co = new KSimpleConfig(path,TRUE); co->setGroup("KDE Desktop Entry"); QString typ = co->readEntry("Type"); QString txt = co->readEntry("Comment"); QString cmd = co->readEntry("Exec"); QString nam = co->readEntry("Name"); if (typ.isEmpty() || txt.isEmpty() || cmd.isEmpty() || nam.isEmpty() || strcmp(typ.data(),"KonsoleApplication")) { delete co; return; // ignore } m_file->insertItem(txt, ++cmd_serial); no2command.insert(cmd_serial,co); }
// Called by constructor (with config = kapp->getConfig()) // and by session-management (with config = sessionconfig). // So it has to apply the settings when reading them. void TEDemo::readProperties(KConfig* config) { config->setGroup("options"); // bad! will no allow us to support multi windows // Global options /////////////////////// setMenuVisible(config->readBoolEntry("menubar visible",TRUE)); setFrameVisible(config->readBoolEntry("has frame",TRUE)); scrollbar_menu_activated(QMIN(config->readUnsignedNumEntry("scrollbar",SCRRIGHT),2)); // not necessary for SM (KTMainWindow does it after), but useful for default settings if (menubar->menuBarPos() != KMenuBar::Floating) { QString entry = config->readEntry("kmenubar"); if (!entry.isEmpty() && entry == "floating") { menubar->setMenuBarPos(KMenuBar::Floating); QString geo = config->readEntry("kmenubargeometry"); if (!geo.isEmpty()) menubar->setGeometry(KWM::setProperties(menubar->winId(), geo)); } else if (!entry.isEmpty() && entry == "top") menubar->setMenuBarPos(KMenuBar::Top); else if (!entry.isEmpty() && entry == "bottom") menubar->setMenuBarPos(KMenuBar::Bottom); } // (geometry stuff removed) done by KTMainWindow for SM, and not needed otherwise // Options that should be applied to all sessions ///////////// // (1) set menu items and TEDemo members setBsHack(config->readBoolEntry("BS hack",TRUE)); setFont(QMIN(config->readUnsignedNumEntry("font",3),7)); // sets n_font and menu item setSchema(config->readEntry("schema","")); // (2) apply to sessions (currently only the 1st one) TESession* s = no2session.find(1); if (s) { s->setFontNo(n_font); s->setSchemaNo(ColorSchema::find(s_schema)->numb); if (b_bshack) s->getEmulation()->setMode(MODE_BsHack); else s->getEmulation()->resetMode(MODE_BsHack); } else { fprintf(stderr,"session 1 not found\n"); } // oops // Default values for startup, changed by "save options". Not used by SM. defaultSize.setWidth ( config->readNumEntry("defaultwidth", 0) ); defaultSize.setHeight( config->readNumEntry("defaultheight", 0) ); }
ColorSchema* ColorSchema::find(const char* path) { ColorSchema* res = 0; QString temp_path; // search for a local schema first if (path[0] != '/') temp_path = kapp->localkdedir() + "/share/apps/konsole/"; temp_path += path; if (QFile::exists(temp_path) == true) res = path2schema.find(temp_path.data()); else { temp_path = kapp->kde_datadir() + "/konsole/"; if (QFile::exists(temp_path) == true) res = path2schema.find(temp_path.data()); } return res ? res : numb2schema.find(0); }
void TEDemo::doneSession(TESession* s, int status) { //printf("%s(%d): Exited:%d ExitStatus:%d\n",__FILE__,__LINE__,WIFEXITED(status),WEXITSTATUS(status)); #if 0 // die silently if (!WIFEXITED((status)) || WEXITSTATUS((status))) { QString str; //FIXME: "Title" is not a precise locator for the message. // The command would be better. str.sprintf(i18n("`%s' terminated abnormally."), s->Title()); if (WIFEXITED((status))) {char rcs[100]; sprintf(rcs,"%d.\n",WEXITSTATUS((status))); str = str + i18n("\nReturn code = ") + rcs; } KMsgBox::message( this, i18n("Error"), str, KMsgBox::EXCLAMATION ); } #endif int no = (int)session2no.find(s); if (!no) return; // oops no2session.remove(no); session2no.remove(s); m_sessions->removeItem(no); s->setConnect(FALSE); // This slot (doneSession) is activated from the Shell when receiving a // SIGCHLD. A lot is done during the signal handler, apparently deleting // the Shell additionally, is sometimes too much, causing something // to get messed up in rare cases. The following causes delete not to // be called from within the signal handler. QTimer::singleShot(100,s,SLOT(terminate())); if (s == se) { // pick a new session se = NULL; QIntDictIterator<TESession> it( no2session ); if ( it.current() ) activateSession(it.currentKey()); else kapp->quit(); } }
void TEDemo::newSession(int i) { char* shell = getenv("SHELL"); if (shell == NULL || *shell == '\0') shell = "/bin/sh"; KSimpleConfig* co = no2command.find(i); if (!co) return; // oops assert( se ); //FIXME: careful here. QString cmd = co->readEntry("Exec"); // not null QString nam = co->readEntry("Name"); // not null QString emu = co->readEntry("Term"); QString sch = co->readEntry("Schema"); QString txt = co->readEntry("Comment"); // not null int fno = QMIN(co->readUnsignedNumEntry("Font",se->fontNo()),7); ColorSchema* schema = sch.isEmpty() ? (ColorSchema*)NULL : ColorSchema::find(sch); //FIXME: schema names here are absolut. Wrt. loadAllSchemas, // relative pathes should be allowed, too. int schmno = schema?schema->numb:se->schemaNo(); if (emu.isEmpty()) emu = se->emuName(); QStrList args; args.append(shell); args.append("-c"); args.append(cmd); TESession* s = new TESession(this,te,args,emu.data(),0); s->setFontNo(fno); s->setSchemaNo(schmno); s->setTitle(txt.data()); addSession(s); runSession(s); // activate and run }
void TEDemo::activateSession(int sn) { TESession* s = no2session.find(sn); if (se) { se->setConnect(FALSE); int no = (int)session2no.find(se); m_sessions->setItemChecked(no,FALSE); } se = s; if (!s) { fprintf(stderr,"session not found\n"); return; } // oops m_sessions->setItemChecked(sn,TRUE); setSchema(s->schemaNo()); //FIXME: creates flicker? Do only if differs //Set Font. Now setConnect should do the appropriate action. //if the size has changed, a resize event (noticable to the application) //should happen. Else, we could even start the application s->setConnect(TRUE); // does a bulkShow (setImage) setFont(s->fontNo()); //FIXME: creates flicker? //FIXME: check here if we're still alife. // if not, quit, otherwise, // start propagating quit. title = s->Title(); // take title from current session setHeader(); }
ColorSchema* ColorSchema::find(int numb) { ColorSchema* res = numb2schema.find(numb); return res ? res : numb2schema.find(0); }
int ColorSchema::count() { return numb2schema.count(); }
static void read_bodies(const char * path, QIntDict<char> & bodies) { char * s = read_file(path); if (s != 0) { char * p1 = s; char * p2; while ((p2 = strstr(p1, BodyPrefix)) != 0) { p2 += BodyPrefixLength; char * body; long id = strtol(p2, &body, 16); if (body != (p2 + 8)) { UmlCom::trace(QCString("<font color =\"red\"> Error in ") + path + " : invalid preserve body identifier</font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("read_bodies 1"); } if (bodies.find(id) != 0) { UmlCom::trace(QCString("<font color =\"red\"> Error in ") + path + " : preserve body identifier used twice</font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("read_bodies 2"); } if (*body == '\r') body += 1; if (*body == '\n') body += 1; else { UmlCom::trace(QCString("<font color =\"red\"> Error in ") + path + " : invalid preserve body block, end of line expected</font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("read_bodies 3"); } if (((p1 = strstr(body, BodyPostfix)) == 0) || (strncmp(p1 + BodyPostfixLength, p2, 8) != 0)) { UmlCom::trace(QCString("<font color =\"red\"> Error in ") + path + " : invalid preserve body block, wrong balanced</font><br>"); UmlCom::bye(n_errors() + 1); UmlCom::fatal_error("read_bodies 4"); } p2 = p1; while ((p2 != body) && (p2[-1] != '\n')) p2 -= 1; *p2 = 0; int len = p2 - body + 1; char * b = new char[len]; memcpy(b, body, len); bodies.insert(id, b); p1 += BodyPostfixLength + 8; } delete [] s; } }
void ColorSchema::addSchema() { numb2schema.insert(numb,this); path2schema.insert(path.data(),this); }
void PukeController::closefd(int fd) { if(bClosing == TRUE) return; bClosing = TRUE; if(qidConnectFd[fd] == NULL){ kdDebug(5008) << "PukeController: Connect table NULL, closed twice?" << endl; return; } // Shutof the listener before closing the socket, just in case. qidConnectFd[fd]->sr->setEnabled(FALSE); // Shut them off qidConnectFd[fd]->sw->setEnabled(FALSE); delete qidConnectFd[fd]->sr; delete qidConnectFd[fd]->sw; qidConnectFd[fd]->server.truncate(0); qidConnectFd.remove(fd); close(fd); /* * Now let's remove all traces of the widgets */ QIntDict<WidgetS> *qidWS = WidgetList[fd]; if(qidWS == 0){ kdDebug(5008) << "WidgetRunner:: Close called twice?" << endl; bClosing = FALSE; return; } qidWS->remove(PUKE_CONTROLLER); do { QIntDictIterator<WidgetS> it(*qidWS); if(it.count() == 0){ kdDebug(5008) << "WidgetRunner: nothing left to delete\n" << endl; break; } PObject *po = 0x0; while(it.current()){ /* * Delete all the layouts first * */ if(it.current()->type == POBJECT_LAYOUT){ po = it.current()->pwidget; break; } ++it; } if(po != 0x0){ po->manTerm(); delete po; continue; } /* * reset */ it.toFirst(); po = it.current()->pwidget; po->manTerm(); delete po; } while (qidWS->count() > 0); WidgetList.remove(fd); bClosing = FALSE; }
bool KeyMappings::apply(int unicode, int keycode, int modifiers, int keymask, bool isPress) { CodeMaps* map; m_isMapped = false; if(m_keymaps.contains(keycode)){ map = m_keymaps[keycode]; if(map->contains(keymask)){ m_isMapped = true; m_keyinfo = (*map)[keymask]; } else { int mask = -1; for(CodeMaps::Iterator it=map->begin(); it!=map->end(); ++it){ if((keymask & it.key()) == it.key() && it.key() > mask){ mask = it.key(); } } if(mask != -1){ m_isMapped = true; m_keyinfo = (*map)[mask]; } } } if(m_isMapped == false){ QWSServer::KeyMap* cache = g_mapCache[keycode]; if(cache == NULL){ cache = new QWSServer::KeyMap(); g_mapCache.insert(keycode, cache); cache->unicode = cache->shift_unicode = cache->ctrl_unicode = 0; } if(cache->unicode == 0 || cache->shift_unicode == 0 || cache->ctrl_unicode == 0){ QChar ch(unicode); if(modifiers & Qt::ControlButton){ cache->ctrl_unicode = unicode; } else if(modifiers & Qt::ShiftButton){ cache->shift_unicode = ch.upper().unicode(); } else { cache->unicode = ch.lower().unicode(); } } m_keyinfo = MapInfo(keycode, 0, cache->unicode, cache->shift_unicode, cache->ctrl_unicode); if(m_keyinfo.isDefined){ setOriginal(unicode, modifiers); } else { setUnicode(unicode); } } #if 1 if(isPress){ if(m_keyinfo.keycode == Qt::Key_CapsLock){ m_capslock = !m_capslock; } } #endif return(m_isMapped); }