/** * load a standard m3u playlist into a list of titles that the tools can handle */ mptitle *loadPlaylist( const char *path ) { FILE *fp; int cnt=0; mptitle *current=NULL; char *buff; char titlePath[MAXPATHLEN]; fp=fopen( path, "r" ); if( !fp ) { addMessage( 0, "Could not open playlist %s", path ); return NULL; } buff=(char*)falloc( MAXPATHLEN, 1 ); while( !feof( fp ) ) { activity( "Loading" ); if( ( fgets( buff, MAXPATHLEN, fp ) != NULL ) && ( strlen( buff ) > 1 ) && ( buff[0] != '#' ) ) { strip( titlePath, buff, MAXPATHLEN ); /* remove control chars like CR/LF */ current=insertTitle( current, titlePath ); /* turn list into playlist too */ } } free( buff ); fclose( fp ); addMessage( 2, "Loaded %s with %i entries.", path, cnt ); return ( current == NULL )?NULL:current->next; }
KexiImageContextMenu::KexiImageContextMenu(QWidget* parent) : KPopupMenu(parent) , d( new Private(this) ) { setName("KexiImageContextMenu"); insertTitle(QString::null); d->insertFromFileAction = new KAction(i18n("Insert From &File..."), SmallIconSet("fileopen"), 0, this, SLOT(insertFromFile()), &d->actionCollection, "insert"); d->insertFromFileAction->plug(this); d->saveAsAction = KStdAction::saveAs(this, SLOT(saveAs()), &d->actionCollection); // d->saveAsAction->setText(i18n("&Save &As...")); d->saveAsAction->plug(this); insertSeparator(); d->cutAction = KStdAction::cut(this, SLOT(cut()), &d->actionCollection); d->cutAction->plug(this); d->copyAction = KStdAction::copy(this, SLOT(copy()), &d->actionCollection); d->copyAction->plug(this); d->pasteAction = KStdAction::paste(this, SLOT(paste()), &d->actionCollection); d->pasteAction->plug(this); d->deleteAction = new KAction(i18n("&Clear"), SmallIconSet("editdelete"), 0, this, SLOT(clear()), &d->actionCollection, "delete"); d->deleteAction->plug(this); #ifdef KEXI_NO_UNFINISHED d->propertiesAction = 0; #else insertSeparator(); d->propertiesAction = new KAction(i18n("Properties"), 0, 0, this, SLOT(showProperties()), &d->actionCollection, "properties"); d->propertiesAction->plug(this); #endif connect(this, SIGNAL(aboutToShow()), this, SLOT(updateActionsAvailability())); }
/** * load a standard m3u playlist into a list of titles that the tools can handle */ struct entry_t *loadPlaylist( const char *path ) { FILE *fp; int cnt; struct entry_t *current=NULL; char *buff; buff=calloc( MAXPATHLEN, sizeof(char) ); if( !buff ) fail( "Out of memory", "", errno ); fp=fopen( path, "r" ); if( !fp ) fail("Couldn't open playlist ", path, errno); while( !feof( fp ) ){ activity("Loading"); buff=fgets( buff, MAXPATHLEN, fp ); if( buff && ( strlen( buff ) > 1 ) && ( buff[0] != '#' ) ){ current=insertTitle( current, buff ); } } fclose( fp ); current=rewindTitles( current ); if( _ftverbosity > 2 ) { printf("Loaded %s with %i entries.\n", path, cnt ); } return current; }
/* * Steps recursively through a directory and collects all music files in a list * curdir: current directory path * files: the list to store filenames in * returns the LAST entry of the list. So the next item is the first in the list */ mptitle *recurse( char *curdir, mptitle *files ) { char dirbuff[2*MAXPATHLEN]; struct dirent **entry; int num, i; if( '/' == curdir[strlen( curdir )-1] ) { curdir[strlen( curdir )-1]=0; } addMessage( 3, "Checking %s", curdir ); /* get all music files */ num = getMusic( curdir, &entry ); if( num < 0 ) { addMessage( 0, "getMusic failed in %s", curdir ); return files; } for( i=0; i<num; i++ ) { activity( "Scanning" ); sprintf( dirbuff, "%s/%s", curdir, entry[i]->d_name ); files=insertTitle( files, dirbuff ); free( entry[i] ); } free( entry ); /* step down subdirectories */ num=getDirs( curdir, &entry ); if( num < 0 ) { addMessage( 0, "getDirs failed on %s", curdir ); return files; } for( i=0; i<num; i++ ) { sprintf( dirbuff, "%s/%s", curdir, entry[i]->d_name ); files=recurse( dirbuff, files ); free( entry[i] ); } free( entry ); return files; }
void RemoteMenu::initialize() { int id = 0; if (KickerSettings::showMenuTitles()) { insertTitle(i18n("Network Folders")); } id = insertItem(SmallIcon("wizard"), i18n("Add Network Folder")); connectItem(id, this, SLOT(startWizard())); id = insertItem(SmallIcon("kfm"), i18n("Manage Network Folders")); connectItem(id, this, SLOT(openRemoteDir())); insertSeparator(); m_desktopMap.clear(); QStringList names_found; QStringList dirList = KGlobal::dirs()->resourceDirs("remote_entries"); QStringList::ConstIterator dirpath = dirList.begin(); QStringList::ConstIterator end = dirList.end(); for(; dirpath!=end; ++dirpath) { QDir dir = *dirpath; if (!dir.exists()) continue; QStringList filenames = dir.entryList( QDir::Files | QDir::Readable ); QStringList::ConstIterator name = filenames.begin(); QStringList::ConstIterator endf = filenames.end(); for(; name!=endf; ++name) { if (!names_found.contains(*name)) { names_found.append(*name); QString filename = *dirpath+*name; KDesktopFile desktop(filename); id = insertItem(SmallIcon(desktop.readIcon()), desktop.readName()); m_desktopMap[id] = filename; } } } }
int main() { int** grid = initializeMatrix(); int score, force_exit, actualSelection = -1; st = GetStdHandle(STD_OUTPUT_HANDLE); restore_colorProfile(0); allocateTail(&(Snake.tail), NULL, 0); while (actualSelection != 0) { mainMenuGraphics(); actualSelection = mainMenu(1); if (actualSelection == 1) { actualSelection = 0; graphics_SelectGameMode(); while ((actualSelection != 1) && (actualSelection != 2)) { actualSelection = mainMenu(2); } int gameMode = graphics_levelSelect(); initializeNewGame(grid, &score, &force_exit); insertTitle(); drawInGameBorder(); displayPauseInstructions(); drawSnake(0, grid); updateScore(score); assignSnake2Matrix(grid, 1); addFood(grid); newGame(grid, &score, &force_exit, actualSelection - 1, gameMode); if (!force_exit) { _getch(); } clear_screen(); restoreSnakeLength(); } else if (actualSelection == 2) { instructions(); } } return 0; }
void KWindowListMenu::init() { int i, d; i = 0; int nd = twin_module->numberOfDesktops(); int cd = twin_module->currentDesktop(); WId active_window = twin_module->activeWindow(); // Make sure the popup is not too wide, otherwise clicking in the middle of kdesktop // wouldn't leave any place for the popup, and release would activate some menu entry. int maxwidth = kapp->desktop()->screenGeometry( this ).width() / 2 - 100; clear(); map.clear(); int unclutter = insertItem( i18n("Unclutter Windows"), this, TQT_SLOT( slotUnclutterWindows() ) ); int cascade = insertItem( i18n("Cascade Windows"), this, TQT_SLOT( slotCascadeWindows() ) ); // if we only have one desktop we won't be showing titles, so put a separator in if (nd == 1) { insertSeparator(); } TQValueList<KWin::WindowInfo> windows; for (TQValueList<WId>::ConstIterator it = twin_module->windows().begin(); it != twin_module->windows().end(); ++it) { windows.append( KWin::windowInfo( *it, NET::WMDesktop )); } bool show_all_desktops_group = ( nd > 1 ); for (d = 1; d <= nd + (show_all_desktops_group ? 1 : 0); d++) { bool on_all_desktops = ( d > nd ); int items = 0; if (!active_window && d == cd) setItemChecked(1000 + d, true); NameSortedInfoList list; list.setAutoDelete(true); for (TQValueList<KWin::WindowInfo>::ConstIterator it = windows.begin(); it != windows.end(); ++it) { if (((*it).desktop() == d) || (on_all_desktops && (*it).onAllDesktops()) || (!show_all_desktops_group && (*it).onAllDesktops())) { list.inSort(new KWin::WindowInfo( (*it).win(), NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType, NET::WM2GroupLeader | NET::WM2TransientFor )); } } for (KWin::WindowInfo* info = list.first(); info; info = list.next(), ++i) { TQString itemText = KStringHandler::cPixelSqueeze(info->visibleNameWithState(), fontMetrics(), maxwidth); NET::WindowType windowType = info->windowType( NET::NormalMask | NET::DesktopMask | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask ); if ( (windowType == NET::Normal || windowType == NET::Unknown || (windowType == NET::Dialog && standaloneDialog( info, list ))) && !(info->state() & NET::SkipTaskbar) ) { TQPixmap pm = KWin::icon(info->win(), 16, 16, true ); items++; // ok, we have items on this desktop, let's show the title if ( items == 1 && nd > 1 ) { if( !on_all_desktops ) insertTitle(twin_module->desktopName( d ), 1000 + d); else insertTitle(i18n("On All Desktops"), 2000 ); } // Avoid creating unwanted accelerators. itemText.replace('&', TQString::fromLatin1("&&")); insertItem( pm, itemText, i); map.insert(i, info->win()); if (info->win() == active_window) setItemChecked(i, true); } } if (d == cd) { setItemEnabled(unclutter, items > 0); setItemEnabled(cascade, items > 0); } } // no windows? if (i == 0) { if (nd > 1) { // because we don't have any titles, nor a separator insertSeparator(); } setItemEnabled(insertItem(i18n("No Windows")), false); } }
void PanelBrowserMenu::initialize() { _lastpress = QPoint(-1, -1); // don't change menu if already visible if (isVisible()) return; if (_dirty) { // directory content changed while menu was visible slotClear(); setInitialized(false); _dirty = false; } if (initialized()) return; setInitialized(true); // start watching if not already done if (!_dirWatch.contains(path())) _dirWatch.addDir( path() ); // setup icon map initIconMap(); // read configuration KConfig *c = KGlobal::config(); c->setGroup("menus"); _showhidden = c->readBoolEntry("ShowHiddenFiles", false); _maxentries = c->readNumEntry("MaxEntries2", 30); // clear maps _filemap.clear(); _mimemap.clear(); int filter = QDir::Dirs | QDir::Files; if(_showhidden) filter |= QDir::Hidden; QDir dir(path(), QString::null, QDir::DirsFirst | QDir::Name | QDir::IgnoreCase, filter); // does the directory exist? if (!dir.exists()) { insertItem(i18n("Failed to Read Folder")); return; } // get entry list const QFileInfoList *list = dir.entryInfoList(); // no list -> read error if (!list) { insertItem(i18n("Failed to Read Folder")); return; } KURL url; url.setPath(path()); if (!kapp->authorizeURLAction("list", KURL(), url)) { insertItem(i18n("Not Authorized to Read Folder")); return; } // insert file manager and terminal entries // only the first part menu got them if(_startid == 0 && !_filesOnly) { insertTitle(path()); insertItem(CICON("kfm"), i18n("Open in File Manager"), this, SLOT(slotOpenFileManager())); if (kapp->authorize("shell_access")) insertItem(CICON("terminal"), i18n("Open in Terminal"), this, SLOT(slotOpenTerminal())); } bool first_entry = true; bool dirfile_separator = false; int item_count = 0; int run_id = _startid; // get list iterator QFileInfoListIterator it(*list); // jump to startid it += _startid; // iterate over entry list for (; it.current(); ++it) { // bump id run_id++; QFileInfo *fi = it.current(); // handle directories if (fi->isDir()) { QString name = fi->fileName(); // ignore . and .. entries if (name == "." || name == "..") continue; QPixmap icon; QString path = fi->absFilePath(); // parse .directory if it does exist if (QFile::exists(path + "/.directory")) { KSimpleConfig c(path + "/.directory", true); c.setDesktopGroup(); QString iconPath = c.readEntry("Icon"); if ( iconPath.startsWith("./") ) iconPath = path + '/' + iconPath.mid(2); icon = KGlobal::iconLoader()->loadIcon(iconPath, KIcon::Small, KIcon::SizeSmall, KIcon::DefaultState, 0, true); if(icon.isNull()) icon = CICON("folder"); name = c.readEntry("Name", name); } // use cached folder icon for directories without special icon if (icon.isNull()) icon = CICON("folder"); // insert separator if we are the first menu entry if(first_entry) { if (_startid == 0 && !_filesOnly) insertSeparator(); first_entry = false; } // append menu entry PanelBrowserMenu *submenu = new PanelBrowserMenu(path, this); submenu->_filesOnly = _filesOnly; append(icon, name, submenu); // bump item count item_count++; dirfile_separator = true; } // handle files else if(fi->isFile()) { QString name = fi->fileName(); QString title = KIO::decodeFileName(name); QPixmap icon; QString path = fi->absFilePath(); bool mimecheck = false; // .desktop files if(KDesktopFile::isDesktopFile(path)) { KSimpleConfig c(path, true); c.setDesktopGroup(); title = c.readEntry("Name", title); QString s = c.readEntry("Icon"); if(!_icons->contains(s)) { icon = KGlobal::iconLoader()->loadIcon(s, KIcon::Small, KIcon::SizeSmall, KIcon::DefaultState, 0, true); if(icon.isNull()) { QString type = c.readEntry("Type", "Application"); if (type == "Directory") icon = CICON("folder"); else if (type == "Mimetype") icon = CICON("txt"); else if (type == "FSDevice") icon = CICON("chardevice"); else icon = CICON("exec"); } else _icons->insert(s, icon); } else icon = CICON(s); } else { // set unknown icon icon = CICON("unknown"); // mark for delayed mimetime check mimecheck = true; } // insert separator if we are the first menu entry if(first_entry) { if(_startid == 0 && !_filesOnly) insertSeparator(); first_entry = false; } // insert separator if we we first file after at least one directory if (dirfile_separator) { insertSeparator(); dirfile_separator = false; } // append file entry append(icon, title, name, mimecheck); // bump item count item_count++; } if(item_count == _maxentries) { // Only insert a "More" item if there are actually more items. ++it; if( it.current() ) { insertSeparator(); append(CICON("kdisknav"), i18n("More"), new PanelBrowserMenu(path(), this, 0, run_id)); } break; } } #if 0 // WABA: tear off handles don't work together with dynamically updated // menus. We can't update the menu while torn off, and we don't know // when it is torn off. if(KGlobalSettings::insertTearOffHandle() && item_count > 0) insertTearOffHandle(); #endif adjustSize(); QString dirname = path(); int maxlen = contentsRect().width() - 40; if(item_count == 0) maxlen = fontMetrics().width(dirname); if (fontMetrics().width(dirname) > maxlen) { while ((!dirname.isEmpty()) && (fontMetrics().width(dirname) > (maxlen - fontMetrics().width("...")))) dirname = dirname.remove(0, 1); dirname.prepend("..."); } setCaption(dirname); // setup and start delayed mimetype check timer if(_mimemap.count() > 0) { if(!_mimecheckTimer) _mimecheckTimer = new QTimer(this); connect(_mimecheckTimer, SIGNAL(timeout()), SLOT(slotMimeCheck())); _mimecheckTimer->start(0); } }