void MainWindow::scanWorlds() { ui->menuOpen_World->clear(); bool enabled = false; int key = 0; for (const QString &worldDir : settings->getWorlds()) { QDir dir(worldDir); QDirIterator it(dir); QList<QAction *> actions; while (it.hasNext()) { it.next(); if (it.fileName().endsWith(".wld")) { QString name = worldName(it.filePath()); if (!name.isNull()) { QAction *w = new QAction(this); w->setText(name); w->setData(it.filePath()); if (key < 9) { w->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1 + key++)); w->setShortcutContext(Qt::ApplicationShortcut); } connect(w, SIGNAL(triggered()), this, SLOT(openWorld())); actions.append(w); } } } if (!actions.isEmpty()) { ui->menuOpen_World->addSection(worldDir); ui->menuOpen_World->addActions(actions); enabled = true; } } ui->menuOpen_World->setDisabled(!enabled); }
void Icon::quit() { // Save icons for persistency if ((! taken) && (! remove) && *names.url) { char ficon[URL_LEN]; Cache::file(names.url, ficon); if (chdir(::g.env.icons()) != -1 ) { struct stat bufstat; if (stat(worldName(), &bufstat) < 0) mkdir(worldName(), 0700); chdir(worldName()); FILE *fp; if ((fp = File::openFile(ficon, "r")) != NULL) { File::closeFile(fp); unlink(ficon); } if ((fp = File::openFile(ficon, "w")) != NULL) { char buf[BUFSIZ]; memset(buf, 0, sizeof(buf)); sprintf(buf, "name=\"%s\" pos=\"%.2f %.2f %.2f %.2f %.2f\" owner=\"%s\" solid dim=\"%.2f %.2f %.2f\" dif=\"%s\" xn=\"%s\" ", getInstance(), pos.x, pos.y, pos.z, pos.az, pos.ax, names.owner[0] ? names.owner : "", WIDTH, DEPTH, HEIGHT, COLOR, tex); strcat(buf, "\n"); fputs(buf, fp); File::closeFile(fp); } chdir(::g.env.cwd()); } else error("can't chdir to %s", ::g.env.icons()); } if (tex) delete[] tex; free(ifile); ifile = NULL; if (ofile) delete[] ofile; free(vref); vref = NULL; }