void QMathMLFileViewer::fileFind( QStringList& files, const QDir& rootDir, const QStringList& mask, QProgressDialog *progressDlg ) { QCoreApplication::processEvents(); if( progressDlg->wasCanceled() ) return; QStringList::const_iterator item; QStringList newFiles = rootDir.entryList(QStringList(mask), QDir::Files | QDir::NoSymLinks, QDir::Name); if( newFiles.size() ) { for( item = newFiles.constBegin(); item != newFiles.constEnd(); item++ ) { QCoreApplication::processEvents(); if( progressDlg->wasCanceled() ) return; files.append(m_currentDir.relativeFilePath(rootDir.absoluteFilePath(*item))); } } if( progressDlg->value() < progressDlg->maximum() - 1 ) progressDlg->setValue( progressDlg->value() + 1 ); QStringList newDirs = rootDir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDir::Name); progressDlg->setMaximum( progressDlg->maximum() + newDirs.size() + 1 ); for( item = newDirs.constBegin(); item != newDirs.constEnd(); item++ ) { if( progressDlg->value() < progressDlg->maximum() - 1 ) progressDlg->setValue( progressDlg->value() + 1 ); QCoreApplication::processEvents(); if( progressDlg->wasCanceled() ) return; QDir itemDir( rootDir ); if( itemDir.cd(*item) ) fileFind( files, itemDir, mask, progressDlg ); } }
static int writeFileConfig(const char *configName, const char *imageName) { // Set the wallpaper in the requested config file. int status = 0; file f; memset(&f, 0, sizeof(file)); status = fileFind(configName, NULL); if (status < 0) { // The file doesn't exist. Try to create it. status = fileOpen(configName, (OPENMODE_WRITE | OPENMODE_CREATE), &f); if (status < 0) return (status); // Now close the file fileClose(&f); } // Save the wallpaper variable if (imageName) status = configSet(configName, "background.image", imageName); else status = configUnset(configName, "background.image"); return (status); }
byte *cCastleManager::fileLoad( string pFilename, size_t &pBufferSize ) { byte *buffer = 0; size_t size; // Attempt to load from a D64 buffer = diskLoadFile( pFilename, pBufferSize ); // Load from local if that fails if(!pBufferSize) { sFileLocal *file = fileFind( pFilename ); if(!file) { buffer = local_FileRead( pFilename, "", size, false ); if(!buffer) return 0; mFiles.push_back( file = new sFileLocal( pFilename, buffer, size )); } buffer = file->mBuffer; pBufferSize = file->mBufferSize; } return buffer; }
void cCastleManager::localLoadCastles() { vector<string> files = directoryList( "castle", "Z", false); vector<string>::iterator fileIT; for( fileIT = files.begin(); fileIT != files.end(); ++fileIT ) { sFileLocal *file = fileFind( (*fileIT) ); if(!file) { size_t size = 0; byte *buffer = local_FileRead( (*fileIT) , "castles", size, false ); if(buffer) mFiles.push_back( file = new sFileLocal( (*fileIT), buffer, size )); else continue; } cCastleInfoLocal *local = new cCastleInfoLocal( this, file ); // Dont add castles with the same name as already existing castles if( castleInfoGet( local->nameGet() ) ) { delete local; continue; } mCastles.push_back( local ); } }
void QMathMLFileViewer::fileFind() { filesTable->setRowCount(0); QString fileName = fileComboBox->currentText(); QString path = directoryComboBox->currentText(); updateComboBox(fileComboBox); updateComboBox(directoryComboBox); m_currentDir = QDir(path); if( fileName.isEmpty() ) fileName = DEFAULT_MASK; //QApplication::setOverrideCursor( Qt::WaitCursor ); QStringList files; if( isRecursive() ) { QProgressDialog progress("Searching files...", "Abort Search", 0, 100, this); progress.setWindowModality(Qt::WindowModal); progress.setMinimumDuration( 500 ); progress.setValue( 0 ); fileFind( files, m_currentDir, QStringList(fileName), &progress ); //progress.setValue( 100 + files.size() ); progress.setValue( progress.maximum() ); } else { //QStringList newFiles = m_currentDir.entryList(QStringList(fileName), QDir::Files | QDir::NoSymLinks); //for( QStringList::const_iterator item = newFiles.constBegin(); item != newFiles.constEnd(); item++ ) // files.append(m_currentDir.absoluteFilePath(*item)); files = m_currentDir.entryList(QStringList(fileName), QDir::Files | QDir::NoSymLinks); } if(files.size() > 0) { filesTable->show(); showFiles(files); filesTable->resizeRowsToContents(); filesTable->resizeColumnsToContents(); foundMessage->setText(QString(tr("%1 file(s) shown of %2 found").arg(filesTable->rowCount()).arg(files.size()))); emit hasFound( true ); } else { filesTable->hide(); foundMessage->setText(QString(tr("No files found to match %1")).arg(fileName)); emit hasFound( false ); } //QApplication::restoreOverrideCursor(); }
QHBoxLayout* QMathMLFileViewer::setupToolLayout() { QHBoxLayout *toolLayout = new QHBoxLayout(); QToolButton *btnRefresh = new QToolButton(); btnRefresh->setIcon(QIcon(":/images/reload.png")); //btnRefresh->setIconSize(m_iconSize); btnRefresh->setToolTip(tr("Refresh contents of the current directory")); connect(btnRefresh, SIGNAL(clicked()), this, SLOT(fileRefresh())); toolLayout->addWidget( btnRefresh ); QToolButton *btnView = new QToolButton(); btnView->setIcon(QIcon(":/images/printpreview.png")); //btnView->setIconSize(m_iconSize); btnView->setToolTip(tr("Open the selected file as a new read-only window in the editor - for viewing purposes only")); connect(btnView, SIGNAL(clicked()), this, SLOT(fileLoad())); connect(this, SIGNAL(hasSelectedItem(bool)), btnView, SLOT(setEnabled(bool))); btnView->setEnabled( false ); toolLayout->addWidget( btnView ); QToolButton *btnOpen = new QToolButton(); btnOpen->setIcon(QIcon(":/images/open.png")); //btnOpen->setIconSize(m_iconSize); btnOpen->setToolTip(tr("Open the selected file as a new window in the editor")); connect(btnOpen, SIGNAL(clicked()), this, SLOT(fileOpen())); connect(this, SIGNAL(hasSelectedItem(bool)), btnOpen, SLOT(setEnabled(bool))); btnOpen->setEnabled( false ); toolLayout->addWidget( btnOpen ); toolLayout->addSpacing( 12 ); QLabel *labelMask = new QLabel(tr("Mask:")); fileComboBox = createComboBox(tr(DEFAULT_MASK)); fileComboBox->setMinimumWidth( 80 ); //fileComboBox->setIconSize(m_iconSize); toolLayout->addWidget( labelMask ); toolLayout->addWidget( fileComboBox ); QToolButton *btnFind = new QToolButton(); btnFind->setIcon(QIcon(":/images/find.png")); //btnFind->setIconSize(m_iconSize); btnFind->setToolTip(tr("Find all files with a given name starting from the current directory")); connect(btnFind, SIGNAL(clicked()), this, SLOT(fileFind())); toolLayout->addWidget( btnFind ); btnRecursive = new QToolButton(); btnRecursive->setObjectName("__qt__fmlide_widget_QMathMLFileViewer_button_Recursive"); btnRecursive->setIcon(QIcon(":/images/contents.png")); btnRecursive->setToolTip(tr("Set on/off recursive search from the current folder")); btnRecursive->setToolButtonStyle( Qt::ToolButtonIconOnly ); btnRecursive->setCheckable( true ); btnRecursive->setChecked( isRecursive() ); connect(btnRecursive, SIGNAL(toggled(bool)), this, SLOT(setRecursive(bool))); toolLayout->addWidget( btnRecursive ); QToolButton *btnBack = new QToolButton(); btnBack->setIcon(QIcon(":/images/back.png")); //btnBack->setIconSize(m_iconSize); btnBack->setToolTip(tr("Select the previous found file")); connect(btnBack, SIGNAL(clicked()), this, SLOT(fileBack())); connect(this, SIGNAL(hasFound(bool)), btnBack, SLOT(setEnabled(bool))); btnBack->setEnabled( false ); toolLayout->addWidget( btnBack ); QToolButton *btnForward = new QToolButton(); btnForward->setIcon(QIcon(":/images/forward.png")); //btnForward->setIconSize(m_iconSize); btnForward->setToolTip(tr("Select the next found file")); connect(btnForward, SIGNAL(clicked()), this, SLOT(fileForward())); connect(this, SIGNAL(hasFound(bool)), btnForward, SLOT(setEnabled(bool))); btnForward->setEnabled( false ); toolLayout->addWidget( btnForward ); toolLayout->addStretch( 1 ); return toolLayout; }
int main(int argc, char *argv[]) { int status = 0; disk sysDisk; char fileName[MAX_PATH_NAME_LENGTH]; setlocale(LC_ALL, getenv(ENV_LANG)); textdomain("wallpaper"); // Only work in graphics mode if (!graphicsAreEnabled()) { printf(_("\nThe \"%s\" command only works in graphics mode\n"), argv[0]); return (status = ERR_NOTINITIALIZED); } memset(&sysDisk, 0, sizeof(disk)); memset(fileName, 0, MAX_PATH_NAME_LENGTH); // Find out whether we are currently running on a read-only filesystem if (!fileGetDisk(PATH_SYSTEM, &sysDisk)) readOnly = sysDisk.readOnly; if (argc < 2) { // The user did not specify a file. We will prompt them. status = windowNewFileDialog(NULL, _("Enter filename"), _("Please choose the background image:"), PATH_SYSTEM_WALLPAPER, fileName, MAX_PATH_NAME_LENGTH, 1); if (status != 1) { if (!status) return (status); printf("%s", _("No filename specified\n")); return (status); } } else { strncpy(fileName, argv[1], MAX_PATH_NAME_LENGTH); } if (strncmp(fileName, "none", MAX_PATH_NAME_LENGTH)) { status = fileFind(fileName, NULL); if (status < 0) { printf("%s", _("File not found\n")); return (status); } windowShellTileBackground(fileName); } else { windowShellTileBackground(NULL); } status = writeConfig(fileName); return (status); }
static int viewFile(const char *fileName) { int status = 0; file theFile; char *fileBuffer = NULL; int charEntered = 0; int charsSoFar = 0; int cursorPos1, cursorPos2; textAttrs attrs; char buffer[32]; unsigned count1; int count2; // Initialize stack data memset(&theFile, 0, sizeof(file)); memset(&attrs, 0, sizeof(textAttrs)); attrs.flags = TEXT_ATTRS_REVERSE; // Call the "find file" routine to see if we can get the file status = fileFind(fileName, &theFile); if (status < 0) return (status); // Make sure the file isn't empty. We don't want to try reading // data from a nonexistent place on the disk. if (theFile.size == 0) // It is empty, so skip it return (status = 0); // The file exists and is non-empty. That's all we care about (we // don't care at this point, for example, whether it's a file or a // directory. Read it into memory and print it on the screen. // Allocate a buffer to store the file contents in fileBuffer = malloc((theFile.blocks * theFile.blockSize) + 1); if (!fileBuffer) return (status = ERR_MEMORY); status = fileOpen(fileName, OPENMODE_READ, &theFile); if (status < 0) { free(fileBuffer); return (status); } status = fileRead(&theFile, 0, theFile.blocks, fileBuffer); if (status < 0) { free(fileBuffer); return (status); } charsSoFar = 0; // Print the file, one screen at a time for (count1 = 0; count1 < theFile.size; count1 ++) { // Are we at the end of a screenful of data? if (charsSoFar >= (screenColumns * (screenRows - 1))) { snprintf(buffer, 32, _("--More--(%d%%)"), ((count1 * 100) / theFile.size)); textPrintAttrs(&attrs, buffer); // Wait for user input textInputSetEcho(0); charEntered = getchar(); textInputSetEcho(1); // Erase the "more" thing cursorPos1 = textGetColumn(); for (count2 = 0; count2 < cursorPos1; count2++) textBackSpace(); // Did the user want to quit or anything? if (charEntered == (int) 'q') break; // Another screenful? else if (charEntered == (int) ' ') charsSoFar = 0; // Another lineful else charsSoFar -= screenColumns; // Continue, fall through } // Look out for tab characters if (fileBuffer[count1] == (char) 9) { // We need to keep track of how many characters get printed cursorPos1 = textGetColumn(); textTab(); cursorPos2 = textGetColumn(); if (cursorPos2 >= cursorPos1) charsSoFar += (cursorPos2 - cursorPos1); else charsSoFar += (screenColumns - (cursorPos1 + 1)) + (cursorPos2 + 1); } // Look out for newline characters else if (fileBuffer[count1] == (char) 10) { // We need to keep track of how many characters get printed cursorPos1 = textGetColumn(); textPutc('\n'); charsSoFar += screenColumns - cursorPos1; } else { textPutc(fileBuffer[count1]); charsSoFar += 1; } } // Free the memory free(fileBuffer); return (status = 0); }
int main(int argc, char *argv[]) { // This command is the "touch" command. It does one of two things based // on the filename argument. If the file does not exist, it creates a // new, empty file. If the file does exist, it updates the date and time // of the file to the current date and time. int status = 0; file theFile; int count; setlocale(LC_ALL, getenv(ENV_LANG)); textdomain("touch"); if (argc < 2) { usage(argv[0]); return (status = ERR_ARGUMENTCOUNT); } // Loop through all of our file name arguments for (count = 1; count < argc; count ++) { // Make sure the name isn't NULL if (!argv[count]) return (status = ERR_NULLPARAMETER); // Initialize the file structure memset(&theFile, 0, sizeof(file)); // Call the "find file" routine to see if the file exists status = fileFind(argv[count], &theFile); // Now, either the file exists or it doesn't... if (status < 0) { // The file doesn't exist. We will create the file. status = fileOpen(argv[count], (OPENMODE_WRITE | OPENMODE_CREATE), &theFile); if (status < 0) { errno = status; perror(argv[0]); return (status); } // Now close the file fileClose(&theFile); } else { // The file exists. We need to update the date and time of the // file status = fileTimestamp(argv[count]); if (status < 0) { errno = status; perror(argv[0]); return (status); } } } // Return success return (status = 0); }
static objectKey constructKeyDiag(objectKey parent, keyMap *map, componentParameters *mainParams) { objectKey mainContainer = NULL; objectKey nameContainer = NULL; objectKey rowContainer[4]; char string[32]; componentParameters params; int count = 0; mainContainer = windowNewContainer(parent, "diagContainer", mainParams); if (!mainContainer) return (mainContainer); memset(¶ms, 0, sizeof(componentParameters)); params.gridWidth = 1; params.gridHeight = 1; params.padTop = 5; params.padLeft = 5; params.padRight = 5; params.orientationX = orient_left; params.orientationY = orient_middle; params.flags |= WINDOW_COMPFLAG_FIXEDWIDTH; if (fileFind(PATH_SYSTEM_FONTS "/xterm-normal-10.vbf", NULL) >= 0) fontLoadSystem("xterm-normal-10.vbf", "xterm-normal-10", &(params.font), 1); // Make a container for the name field nameContainer = windowNewContainer(mainContainer, "nameContainer", ¶ms); // The name label and field params.padLeft = 0; nameLabel = windowNewTextLabel(nameContainer, NAME, ¶ms); params.gridX += 1; nameField = windowNewTextField(nameContainer, 30, ¶ms); windowComponentSetData(nameField, map->name, MAX_PATH_LENGTH, 1 /* redraw */); // Make containers for the rows params.gridX = 0; params.padTop = 0; params.padBottom = 0; params.padLeft = 5; params.padRight = 5; params.orientationX = orient_center; params.orientationY = orient_middle; params.flags &= ~WINDOW_COMPFLAG_FIXEDWIDTH; for (count = 0; count < 4; count ++) { params.gridY += 1; if (count == 3) params.padBottom = 5; rowContainer[count] = windowNewContainer(mainContainer, "rowContainer", ¶ms); } // Loop through the key array and set their columns and rows // 2nd row for (count = keyE0; count <= keyBackSpace; count ++) { keyArray[count].buttonColumn = (count - keyE0); keyArray[count].buttonRow = 0; keyArray[count].show = 1; } // 3rd row for (count = keyTab; count <= keyD13; count ++) { keyArray[count].buttonColumn = (count - keyTab); keyArray[count].buttonRow = 1; keyArray[count].show = 1; } // 4th row for (count = keyCapsLock; count <= keyC12; count ++) { keyArray[count].buttonColumn = (count - keyCapsLock); keyArray[count].buttonRow = 2; keyArray[count].show = 1; } keyArray[keyEnter].buttonColumn = (count - keyCapsLock); keyArray[keyEnter].buttonRow = 2; keyArray[keyEnter].show = 1; // Fourth row for (count = keyLShift; count <= keyRShift; count ++) { keyArray[count].show = 1; keyArray[count].buttonColumn = (count - keyLShift); keyArray[count].buttonRow = 3; } for (count = 0; count < KEYBOARD_SCAN_CODES; count ++) if (univMap.regMap[count] != (unsigned char) -1) keyArray[count].grey = 1; params.padTop = 0; params.padBottom = 0; params.padLeft = 0; params.padRight = 0; // Now put the buttons in their containers for (count = 0; count < KEYBOARD_SCAN_CODES; count ++) { if (keyArray[count].show) { makeButtonString(&keyArray[count], string); params.gridX = keyArray[count].buttonColumn; keyArray[count].button = windowNewButton(rowContainer[keyArray[count].buttonRow], string, NULL, ¶ms); windowRegisterEventHandler(keyArray[count].button, &editKeyHandler); if (fontGetPrintedWidth(params.font, string) < fontGetPrintedWidth(params.font, "@@@")) { windowComponentSetWidth(keyArray[count].button, fontGetPrintedWidth(params.font, "@@@")); } if (keyArray[count].grey) windowComponentSetEnabled(keyArray[count].button, 0); } } return (mainContainer); }
int main(int argc, char *argv[]) { int status = 0; int print = 0; char *mapName = NULL; char *saveName = NULL; char *dirName = NULL; char opt; int count; setlocale(LC_ALL, getenv(ENV_LANG)); textdomain("keymap"); // Graphics enabled? graphics = graphicsAreEnabled(); // Check options while (strchr("psT:?", (opt = getopt(argc, argv, "ps:T")))) { switch (opt) { case 'p': // Just print out the map, if we're in text mode print = 1; break; case 's': // Save the map to a file if (!optarg) { fprintf(stderr, "%s", _("Missing filename argument for -s " "option\n")); usage(argv[0]); return (status = ERR_NULLPARAMETER); } saveName = optarg; break; case 'T': // Force text mode graphics = 0; break; case ':': fprintf(stderr, _("Missing parameter for %s option\n"), argv[optind - 1]); usage(argv[0]); return (status = ERR_NULLPARAMETER); default: fprintf(stderr, _("Unknown option '%c'\n"), optopt); usage(argv[0]); return (status = ERR_INVALID); } } cwd = malloc(MAX_PATH_LENGTH); selectedMap = malloc(sizeof(keyMap)); if (!cwd || !selectedMap) { status = ERR_MEMORY; goto out; } strncpy(cwd, PATH_SYSTEM_KEYMAPS, MAX_PATH_LENGTH); // Get the current map status = keyboardGetMap(selectedMap); if (status < 0) goto out; strncpy(currentName, selectedMap->name, KEYMAP_NAMELEN); mapName = selectedMap->name; // Did the user supply either a map name or a key map file name? if ((argc > 1) && (optind < argc)) { // Is it a file name? status = fileFind(argv[optind], NULL); if (status >= 0) { status = readMap(argv[optind], selectedMap); if (status < 0) goto out; mapName = selectedMap->name; dirName = dirname(argv[optind]); if (dirName) { strncpy(cwd, dirName, MAX_PATH_LENGTH); free(dirName); } } else { // Assume we've been given a map name. mapName = argv[optind]; } if (!graphics && !saveName && !print) { // The user wants to set the current keyboard map to the supplied // name. status = setMap(mapName); goto out; } // Load the supplied map name status = loadMap(mapName); if (status < 0) goto out; } keyArray = malloc(KEYBOARD_SCAN_CODES * sizeof(scanKey)); if (!keyArray) { status = ERR_MEMORY; goto out; } // Make the initial key array based on the current map. makeKeyArray(selectedMap); if (saveName) { // The user wants to save the current keyboard map to the supplied // file name. status = saveMap(saveName); goto out; } status = getMapNameParams(); if (status < 0) goto out; if (graphics) { // Make our window constructWindow(); // Run the GUI windowGuiRun(); // ...and when we come back... windowDestroy(window); } else { if (print) { // Print out the whole keyboard for the selected map printKeyboard(); } else { // Just print the list of map names printf("\n"); for (count = 0; count < numMapNames; count ++) printf("%s%s\n", mapListParams[count].text, (!strcmp(mapListParams[count].text, selectedMap->name)? _(" (current)") : "")); } } status = 0; out: if (cwd) free(cwd); if (selectedMap) free(selectedMap); if (mapListParams) free(mapListParams); if (keyArray) free(keyArray); return (status); }