MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); left_panel=new FilePanel(ui->centralWidget); right_panel=new FilePanel(ui->centralWidget); currentPanel=left_panel; menu=new QMenu; ui->gridLayout->addWidget(left_panel->layoutWidget,1,0,1,1); ui->gridLayout->addWidget(right_panel->layoutWidget,1,1,1,1); connect(left_panel,SIGNAL(tryOpen(QModelIndex)),this,SLOT(open(QModelIndex))); connect(left_panel,SIGNAL(tryJump(QString)),this,SLOT(jumpTo(QString))); connect(left_panel,SIGNAL(panelActivated(FilePanel*)),this,SLOT(setCurrentPanel(FilePanel*))); connect(left_panel,SIGNAL(tryDelete()),this,SLOT(start_del())); connect(right_panel,SIGNAL(tryOpen(QModelIndex)),this,SLOT(open(QModelIndex))); connect(right_panel,SIGNAL(tryJump(QString)),this,SLOT(jumpTo(QString))); connect(right_panel,SIGNAL(panelActivated(FilePanel*)),this,SLOT(setCurrentPanel(FilePanel*))); connect(right_panel,SIGNAL(tryDelete()),this,SLOT(start_del())); initDrives(); connect(right_panel,SIGNAL(tryMount(QString)),this,SLOT(mountDrive(QString))); connect(left_panel,SIGNAL(tryMount(QString)),this,SLOT(mountDrive(QString))); left_panel->setModel(new fileModel); right_panel->setModel(new fileModel); setup_contextMenu(); left_panel->setPopupMenu(menu); right_panel->setPopupMenu(menu); setup_toolbar(); setup_favoritiesPath(); left_panel->loadSettings("Left"); right_panel->loadSettings("Right"); connect(left_panel,SIGNAL(tryDrop(QList<QUrl>,QString,Qt::DropAction)),this,SLOT(drop(QList<QUrl>,QString,Qt::DropAction))); connect(right_panel,SIGNAL(tryDrop(QList<QUrl>,QString,Qt::DropAction)),this,SLOT(drop(QList<QUrl>,QString,Qt::DropAction))); connect(left_panel,SIGNAL(moveChecked(bool)),right_panel,SLOT(checkMove(bool))); connect(right_panel,SIGNAL(moveChecked(bool)),left_panel,SLOT(checkMove(bool))); QFileSystemWatcher *watcher=new QFileSystemWatcher; watcher->addPath("/dev/disk/by-uuid"); connect(watcher,SIGNAL(directoryChanged(QString)),this,SLOT(drivesChanged(QString))); }
void loadProb(const string &prefix) { for (int length = 1; length <= 6; ++ length) { char filename[255]; sprintf(filename, "%s%d.csv", prefix.c_str(), length); FILE* in = tryOpen(filename, "r"); if (in == NULL) { cerr << "[Warning] No length " << length << " phrases." << endl; continue; } getLine(in); double sum = 0; for (;getLine(in);) { vector<string> tokens = splitBy(line, ','); string pattern = tolower(tokens[0]); double value; fromString(tokens[2], value); prob[pattern] = value; sum += value; } //fprintf(stderr, "sum %d = %.6f\n", length, sum); fclose(in); } //cerr << "# prob = " << prob.size() << endl; }
int main(int argc, char *argv[]) { FILE *input; char *fileName = argv[1]; Sphere **sphereList = (Sphere **) malloc(sizeof(Sphere *)); int sphereListLength = 0; View view; Point eyePoint; Light lightSource; Color ambientLight; FILE *output; tryOpen(&input, fileName); readSphereList(&input, sphereList, &sphereListLength); createView(&view); createEyePoint(&eyePoint); createLightSource(&lightSource); createAmbience(&ambientLight); output = fopen("image.ppm", "w"); fprintf(output, "P3\n"); fprintf(output, "%d %d\n", view.width, view.height); fprintf(output, "%d\n\n", 255); castAllRays(&view, &eyePoint, &ambientLight, &lightSource, sphereList, &sphereListLength, &output); free(sphereList); fclose(output); }
int ProviderRs232::writeBytes(const qint64 size, const uint8_t * data) { if (! _blockedForDelay) { if (!_rs232Port.isOpen()) { return tryOpen(5000) ? 0 : -1; } if (_frameDropCounter > 5) { Debug(_log, "%d frames dropped", _frameDropCounter); } _frameDropCounter = 0; _blockedForDelay = true; _bytesToWrite = size; qint64 bytesWritten = _rs232Port.write(reinterpret_cast<const char*>(data), size); if (bytesWritten == -1 || bytesWritten != size) { Warning(_log,"failed writing data"); QTimer::singleShot(500, this, SLOT(unblockAfterDelay())); return -1; } QTimer::singleShot(5000, this, SLOT(unblockAfterDelay())); } else { _frameDropCounter++; } return 0; }
DhcpcdQt::DhcpcdQt() { createActions(); createTrayIcon(); onLine = carrier = false; lastStatus = NULL; aniTimer = new QTimer(this); connect(aniTimer, SIGNAL(timeout()), this, SLOT(animate())); notifier = NULL; retryOpenTimer = NULL; about = NULL; preferences = NULL; wis = new QList<DhcpcdWi *>(); ssidMenu = NULL; qDebug("%s", "Connecting ..."); con = dhcpcd_new(); if (con == NULL) { qCritical("libdhcpcd: %s", strerror(errno)); exit(EXIT_FAILURE); return; } dhcpcd_set_progname(con, "dhcpcd-qt"); dhcpcd_set_status_callback(con, dhcpcd_status_cb, this); dhcpcd_set_if_callback(con, dhcpcd_if_cb, this); dhcpcd_wpa_set_scan_callback(con, dhcpcd_wpa_scan_cb, this); dhcpcd_wpa_set_status_callback(con, dhcpcd_wpa_status_cb, this); tryOpen(); }
void loadPattern(const string &filename) { FILE* in = tryOpen(filename, "r"); for (;getLine(in);) { vector<string> tokens = splitBy(line, ','); string pattern = tolower(tokens[0]); int occurrence; fromString(tokens[1], occurrence); patterns[pattern] = occurrence; prob[pattern] = occurrence; quote[pattern] = parenthesis[pattern] = dash[pattern] = capital[pattern] = total[pattern] = 0; size_t tokensN = splitBy(pattern, ' ').size(); f[pattern].resize(tokensN, 0); sumOutside[pattern].resize(tokensN, 0); tree.add(" " + pattern + " "); } fclose(in); //cerr << "# Pattern = " << prob.size() << endl; tree.make(); //cerr << "Tree is built" << endl; }
Database Database::open(const std::string &filename, int flags) { auto result = tryOpen(filename, flags); if (result.is<Exception>()) { throw result.get<Exception>(); } else { return std::move(result.get<Database>()); } }
void loadStopwords(string stopFile, string idfFile) { FILE* in = tryOpen(idfFile, "r"); for (;getLine(in);) { vector<string> tokens = splitBy(line, ','); if (tokens.size() == 2) { string word = tokens[0]; double idf; fromString(tokens[1], idf); word2idf[word] = idf; } else { cerr << line << endl; } } in = tryOpen(stopFile, "r"); for (;getLine(in);) { stopwords[line] = 1; } }
int main(int argc, char *argv[]) { // Files and such FILE *tab; FILE *newTab; char *inputFilename = argv[1]; char *outputFilename; char inputKey; int keyShift; // Open input file and determine key tryOpen(&tab, inputFilename, "r"); // Process commandline arguments if (argc > 1) { for (int i = 2; i < argc; i++) { // If the number of half steps up is specified if (strcmp(argv[i], "-keyUp") == 0) { keyShift = atoi(argv[i + 1]); // If the number of half steps down is specified } else if (strcmp(argv[i], "-keyDown") == 0) { keyShift = -1 * atoi(argv[i + 1]); // If output filename is specified } else if (strcmp(argv[i], "-o") == 0) { outputFilename = argv[i + 1]; } } } // Name the output file and open it if (outputFilename == NULL) outputFilename = "tab.txt"; tryOpen(&newTab, outputFilename, "w"); // Generate new tab writeNewTab(&tab, &newTab, keyShift); return 0; }
void loadSentences(const string &filename) { FILE* in = tryOpen(filename, "rb"); size_t size; Binary::read(in, size); sentences.resize(size); for (size_t i = 0; i < size; ++ i) { Binary::read(in, sentences[i]); } //cerr << "# Sentences Loaded = " << size << endl; }
void loadPattern(const string &filename) { FILE* in = tryOpen(filename, "r"); for (;getLine(in);) { vector<string> tokens = splitBy(line, ','); string pattern = tolower(tokens[0]); int occurrence; fromString(tokens[1], occurrence); oldProb[pattern] = occurrence; } fclose(in); // cerr << "# old prob = " << oldProb.size() << endl; }
vector<string> loadFeatureTable(const string &filename) { FILE* in = tryOpen(filename, "r"); vector<string> ret; getLine(in); ret.push_back(line); for (;getLine(in);) { vector<string> tokens = splitBy(line, ','); string pattern = tolower(tokens[0]); patterns[pattern] = line; } FOR (iter, patterns) { ret.push_back(iter->second); }
void DhcpcdQt::statusCallback(const char *status) { qDebug("Status changed to %s", status); if (strcmp(status, "down") == 0) { aniTimer->stop(); aniCounter = 0; onLine = carrier = false; setIcon("status", "network-offline"); trayIcon->setToolTip(tr("Not connected to dhcpcd")); /* Close down everything */ if (notifier) { notifier->setEnabled(false); notifier->deleteLater(); notifier = NULL; } if (ssidMenu) { ssidMenu->deleteLater(); ssidMenu = NULL; } preferencesAction->setEnabled(false); if (preferences) { preferences->deleteLater(); preferences = NULL; } } else { bool refresh; if (lastStatus == NULL || strcmp(lastStatus, "down") == 0) { qDebug("Connected to dhcpcd-%s", dhcpcd_version(con)); refresh = true; } else refresh = strcmp(lastStatus, "opened") ? false : true; updateOnline(refresh); } free(lastStatus); lastStatus = strdup(status); if (strcmp(status, "down") == 0) { if (retryOpenTimer == NULL) { retryOpenTimer = new QTimer(this); connect(retryOpenTimer, SIGNAL(timeout()), this, SLOT(tryOpen())); retryOpenTimer->start(DHCPCD_RETRYOPEN); } } }
void Door::bump(Actor* actorBumping) { if(actorBumping == eng->player) { if(isSecret_) { if(eng->map->playerVision[pos_.x][pos_.y]) { tracer << "Door: Player bumped into secret door, with vision in cell" << endl; eng->log->addMessage("That way is blocked."); } else { tracer << "Door: Player bumped into secret door, without vision in cell" << endl; eng->log->addMessage("I bump into something."); } return; } if(isOpen_ == false) { tryOpen(actorBumping); } } }
SoundSource::OpenResult SoundSource::open(const AudioSourceConfig& audioSrcCfg) { close(); // reopening is not supported OpenResult result; try { result = tryOpen(audioSrcCfg); } catch (const std::exception& e) { qWarning() << "Caught unexpected exception from SoundSource::tryOpen():" << e.what(); result = OpenResult::FAILED; } catch (...) { qWarning() << "Caught unknown exception from SoundSource::tryOpen()"; result = OpenResult::FAILED; } if (OpenResult::SUCCEEDED != result) { close(); // rollback } return result; }
/* Read a graph from a text file, using the given representation. Assumes path is a null-terminated string that is valid file path. Assumes file has the specified format. */ GraphInfo readGraph(char* path, int repType) { /* open file, get number of vertices, allocate and initialize GraphInfo */ FILE* infile = tryOpen(path, "r"); int numVerts; fscanf(infile, "%i", &numVerts); GraphInfo gi = (GraphInfo) malloc(sizeof(struct graphinfo)); gi->graph = makeGraph(numVerts, repType); char **vertnames = (char**) malloc(numVerts * sizeof(char *)); gi->vertnames = vertnames; /* get vertex names */ char source[MAX_NAMELEN + 1]; int i = 0; while( i < numVerts && fscanf(infile, "%s", source) != EOF ) { // read, determine length, and make copy in the heap vertnames[i] = (char *) malloc(strlen(source)); strcpy(vertnames[i], source); i++; } /* get the edges */ char target[MAX_NAMELEN + 1]; float weight; int result = fscanf(infile, "%s %s %f", source, target, &weight); while( result != EOF) { if (result >= 2 ) { // read at least two items if (result == 2) // weight not included weight = DEFAULT_WEIGHT; addEdge(gi->graph, indexOf(gi, source), indexOf(gi, target), weight); result = fscanf(infile, "%s %s %f", source, target, &weight); } else { fprintf(stderr, "readGraph fatal error: unexpected file format in %s\n", path); exit(1); } } /* clean up and return */ fclose(infile); return gi; }
void FtpCmd :: run() { lastErr.setOk(); disconnect(ftpconn,0,this,0); connect(ftpconn,SIGNAL(done(bool)),this,SLOT(fin(bool)) ); if(isOpen() or tryOpen()) { if( doFtpCmd() ) { // emit mes("s1"); exec(); // emit mes("s2"); endFtpCmd(); } } else { lastErr.redefine("Not FTP connection"); } emit finished(this); }
void DhcpcdQt::tryOpen() { int fd = dhcpcd_open(con, true); static int last_error; if (fd == -1) { if (errno == EACCES || errno == EPERM) { if ((fd = dhcpcd_open(con, false)) != -1) goto unprived; } if (errno != last_error) { last_error = errno; const char *errt = strerror(errno); qCritical("dhcpcd_open: %s", errt); trayIcon->setToolTip( tr("Error connecting to dhcpcd: %1").arg(errt)); } if (retryOpenTimer == NULL) { retryOpenTimer = new QTimer(this); connect(retryOpenTimer, SIGNAL(timeout()), this, SLOT(tryOpen())); retryOpenTimer->start(DHCPCD_RETRYOPEN); } return; } unprived: /* Start listening to WPA events */ dhcpcd_wpa_start(con); if (retryOpenTimer) { retryOpenTimer->stop(); retryOpenTimer->deleteLater(); retryOpenTimer = NULL; } notifier = new QSocketNotifier(fd, QSocketNotifier::Read); connect(notifier, SIGNAL(activated(int)), this, SLOT(dispatch())); preferencesAction->setEnabled(dhcpcd_privileged(con)); }
void WinService::open() const { if (!tryOpen()) throw NotFoundException("service does not exist", _name); }
bool WinService::isRegistered() const { return tryOpen(); }
int ProviderRs232::open() { return tryOpen(_delayAfterConnect_ms) ? 0 : -1; }