Exemplo n.º 1
0
bool MainWindow::confirmToGo()
{
    if(!isWindowModified())
        return true;

    //show dialogue
    int ret = QMessageBox::warning(this, tr("Save Changes?"),
                                   tr("The document has been modified.\n" "Do you want to save the changes?"),
                                   QMessageBox::Save, QMessageBox::Discard, QMessageBox::Cancel);

    switch (ret) {

    case QMessageBox::Save:
        if(getCurrentFileName().isEmpty())
            on_actionSaveAs_triggered();
        else
            on_actionSave_triggered();

    case QMessageBox::Discard:
        return true;

    default: // QMessageBox::Cancel
        break;
    }
    return false;

}
Exemplo n.º 2
0
void MainWindow::updateRecentFiles()
{
    QString fileName = getCurrentFileName();

    // remove the same fileName in the list as the currentFileName
    recentFiles.removeAll(fileName);

    // remove non-existent files
    for(int i=0; i<recentFiles.count(); i++){
        if(!QFile::exists(recentFiles[i]))
            recentFiles.removeAt(i);
    }

    // prepend curentFileName and remove items above MaxRecentFile
    if(!fileName.isEmpty() && QFile::exists(fileName)){
        recentFiles.prepend(fileName);

        if(recentFiles.count() > MaxRecentFile){
            for(int i=MaxRecentFile; i<recentFiles.count(); i++)
                recentFiles.removeAt(i);
        }
    }

    // update recentFilesAction
    for(int j=0; j<recentFiles.count(); j++){
        recentFilesAction[j]->setText(tr("&%1 %2").arg(j+1)
                               .arg(QFileInfo(recentFiles[j]).fileName()));
        recentFilesAction[j]->setData(recentFiles[j]);
        if(j < recentFiles.count())
            recentFilesAction[j]->setVisible(true);
        else
            recentFilesAction[j]->setVisible(false);
    }
    ui->actionSeperator->setVisible(!recentFiles.isEmpty());
}
Exemplo n.º 3
0
void MainWindow::updateWindowtitle()
{
    QString fileName = getCurrentFileName();
    // get "Untitled" or stripped filename
    fileName = fileName.isEmpty() ? tr("Untitled") :
                                    QFileInfo(fileName).fileName();
    setWindowTitle(tr("%1[*] - %2").arg(fileName).arg("Spreadsheet"));
}
Exemplo n.º 4
0
bool MainWindow::saveFile(const QString &fileName)
{

    if(!spreadsheet->writeFile(fileName)){
        ui->statusBar->showMessage(tr("Saving canceled"), 2000);
        return false;
    }
    setCurrentFileName(fileName);
    ui->statusBar->showMessage(QString("%1 ").arg(getCurrentFileName()) += tr("has been saved"), 2000);

    return true;

}
Exemplo n.º 5
0
void MainWindow::on_actionSave_triggered()
{
    if(!isWindowModified()){
        ui->statusBar->showMessage("Nothing to save", 2000);
        return;
    }

    QString fileName = getCurrentFileName();
    if(fileName.isEmpty()){
        on_actionSaveAs_triggered();
    } else{
        saveFile(fileName);
    }
}
Exemplo n.º 6
0
bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
{
  zipError=UNZ_OK;
  if(mode!=mdUnzip) {
    qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode");
    return false;
  }
  if(fileName.isNull()) {
    hasCurrentFile_f=false;
    return true;
  }
  // Unicode-aware reimplementation of the unzLocateFile function
  if(unzFile_f==NULL) {
    zipError=UNZ_PARAMERROR;
    return false;
  }
  if(fileName.length()>MAX_FILE_NAME_LENGTH) {
    zipError=UNZ_PARAMERROR;
    return false;
  }
  bool sens;
  if(cs==csDefault) {
#ifdef Q_OS_WIN
    sens=false;
#else
    sens=true;
#endif
  } else sens=cs==csSensitive;
  QString lower, current;
  if(!sens) lower=fileName.toLower();
  hasCurrentFile_f=false;
  for(bool more=goToFirstFile(); more; more=goToNextFile()) {
    current=getCurrentFileName();
    if(current.isNull()) return false;
    if(sens) {
      if(current==fileName) break;
    } else {
      if(current.toLower()==lower) break;
    }
  }
  return hasCurrentFile_f;
}