Show
Ignore:
Timestamp:
01/22/10 19:44:34 (2 years ago)
Author:
sven-win
Message:

Umfangreiche Weiterentwicklung (letzte Entwicklung am Netbook). Driver fuer M200 erstmals testweise implementiert; funktioniert(e mit Netbook).

-- Sven @ netboo

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • punch-card-project/trunk/punch-card-editor/src/app/mainwindow.cc

    r58 r59  
    33#include "qpunchcard/widget.h" 
    44#include "deckviewer/navigatormodel.h" 
     5 
     6#include "qpunchcard/jones.h" 
    57 
    68#include <QApplication> 
     
    5658 
    5759void MainWindow::createGraphicalEditor() { 
    58         graphical_editor = new CardEditor(this); // this takes ownership nevertheless 
     60        graphical_editor = new CardEditor(this); // ŽthisŽ takes ownership nevertheless 
    5961        setCentralWidget(graphical_editor); 
    6062        // signale und so: 
     
    9496        // this method will close it when everything went good 
    9597        QFile file(filename); 
    96         const FileFormat* format = FileFormatFactory::createFormat( 
     98        FileFormat format = FileFormatFactory::createFormat( 
    9799                                FileFormatFactory::autoDetectFormat(file) 
    98100                             ); 
    99         Deck* new_deck = new Deck(format); 
     101        Deck* new_deck = new Deck; 
    100102        // Leser anschmeissen 
    101         if( new_deck->read(file) ) { 
     103        if( new_deck->read(format, file) ) { 
    102104                statusBar()->showMessage(QString(tr("Deck read in successfully")), 4000); 
    103         } else 
    104                 qDebug() << "Errors while reading in the Deck."; 
     105        } else { 
     106                QMessageBox::critical(this, tr("Could not open file"), 
     107                                      tr("Could not open file %1 using format %2 for reading. Reason: %3") 
     108                                      .arg(filename).arg(format.getName()).arg(file.errorString()) 
     109                                      ); 
     110                return; 
     111        } 
    105112        // Alte Datei rausschmeissen 
    106113        closeDeck(); 
    107114        // Neue setzen 
    108115        deck = new_deck; 
    109         this->file.setFileName( file.fileName() ); 
    110116        notifyFileOpened(); 
    111117} 
     
    120126                } 
    121127        } else 
    122                 qDebug("notifyFileOpened is supposed to be called when a file was *opened*"); 
     128                qDebug("notifyFileOpened is supposed to be called when a file was *opened*, not closed"); 
    123129} 
    124130 
     
    141147void MainWindow::openFile() { 
    142148        if(maybeSave()) { 
     149                Q_ASSERT(deck); 
    143150                // Oeffnen-Dialog anzeigen. 
    144                 QString filename = QFileDialog::getOpenFileName(this, 
     151                QString new_filename = QFileDialog::getOpenFileName(this, 
    145152                        tr("Open Card Deck File..."), 
    146                         QFileInfo(file).absolutePath(), 
     153                        QFileInfo(deck->getFileName()).absolutePath(), 
    147154                        tr("Jones Emulated Card Decks (*);;Card Editor XML-Files (*.xml *.cml)")); 
    148                 if(!filename.isEmpty()) { 
    149                         loadDeck(filename); 
     155                if(!new_filename.isEmpty()) { 
     156                        loadDeck(new_filename); 
    150157                } 
    151158        } 
     
    153160 
    154161bool MainWindow::saveFile() { 
    155         if(!file.exists() || !deck->canSave()) 
    156                 return saveFileAs(); 
    157         else 
    158                 return deck->save(file); 
     162        return deck->canSave() ? deck->save() : saveFileAs(); 
    159163} 
    160164 
    161165bool MainWindow::saveFileAs() { 
     166        Q_ASSERT(deck); 
    162167        // GUI anzeigen zum Speichern 
    163168        QString filename = QFileDialog::getSaveFileName(this, 
    164169                tr("Save Card Deck File..."), 
    165                 QFileInfo(file).absolutePath(), 
     170                QFileInfo(deck->getFileName()).absolutePath(), 
    166171                tr("Jones Emulator Card Decks (*);;Card Editor XML-Files (*.xml *.cml)")); 
    167172        if(filename.isEmpty()) 
    168173                return false; 
    169         // Eigentlich jetzt: Nachschauen, welches Dateiformat zum Benutzen und so. 
     174        // Eigentlich jetzt: Nachfragen, welches Dateiformat zum Benutzen und so. 
    170175        // stattdessen jetzt mal billig: 
    171         file.setFileName(filename); 
    172         if(deck->canSave()) { 
    173                 // Nutze das bekannte Dateiformat 
    174                 return deck->save(file); 
     176        if(!deck->hasFormat()) { 
     177                // Es fehlt noch ein Format, nutze einfach mal das erstbeste 
     178                deck->setFormat( FileFormatFactory::createFormat(FileFormatFactory::availableFormats()[0]) ); 
     179        } 
     180 
     181        // Eigene Datei benutzen, statt einfach nur deck->save() aufzurufen, um ggf. Fehler und so 
     182        // zurueckzukriegen. 
     183        QFile file(filename); 
     184        if(deck->save(deck->getFormat(), file)) { 
     185                statusBar()->showMessage(QString(tr("Deck written successfully to %1").arg(filename)), 4000); 
     186                return true; 
    175187        } else { 
    176                 // Nutze einfach mal 
    177                 deck->setFormat( new JonesFileFormat ); 
    178                 if(deck->save(file)) { 
    179                         statusBar()->showMessage(QString(tr("Deck written successfully to %1").arg(filename)), 4000); 
    180                         return true; 
    181                 } else { 
    182                         // todo: das hier als qmessagewindow oder so 
    183                         statusBar()->showMessage(QString(tr("Error while writing the deck")), 4000); 
    184                         return false; 
    185                 } 
     188                QMessageBox::critical(this, tr("Saving File failed"), 
     189                                      tr("Could not write card deck to file %1, using format %2. Reason: %3") 
     190                                      .arg(filename).arg(deck->getFormat().getName()).arg(file.errorString()) 
     191                ); 
     192                return false; 
    186193        } 
    187194} 
     
    193200        // Dann abspeichern oder so... hier waere natuerlich auch interessant, 
    194201        // auf bestehende Dateinamen zurueckgreifen zu koennen... 
     202        if(this->text_editors.count() == 0) { 
     203                // no text editor present => ask user if he wants to open one 
     204                if(QMessageBox::question(this, tr("No Text Editor started"), 
     205                        tr("You have not started any Text Editor component yet. " 
     206                           "Each text editor uses his own codec to translate a punch card. " 
     207                           "Hence you need a text editor to export a text using a codec. " 
     208                           "Do you want to open a new text editor?"), 
     209                        QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { 
     210                                this->newTextEditor(); 
     211                } 
     212        } else if(this->text_editors.count() == 1) { 
     213                // exactly *one* text editor present 
     214                Q_ASSERT(text_editors[0]); 
     215                text_editors[0]->exportText(); 
     216        } else { 
     217                // multiple editors present 
     218                // urhm... there *should* have been some other toolbar by now... but there is not... so 
     219                // display some sort of "selection" dialog 
     220                qDebug() << "Select text editor..."; 
     221        } 
    195222} 
    196223 
© 2008 - 2010 Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License