예제 #1
0
/**
 * Charge une note particulière de l'espace
 * de travail
 */
void NotesManager::load(unsigned int id) throw(NoteException)  {
  //On ouvre en lecture le fichier de note
  QFile f(getFilename(id));

  if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
    //On lit la première ligne du texte, pour récupérer son type
    QTextStream stream(&f);
    QString firstLine = stream.readLine();
    f.close();
    //On recupère la factory associée
    NoteFactory *associatedFactory = factories[firstLine];
    if (associatedFactory) {
      notes[id] = associatedFactory->loadNote(id);
    }
    else {
      /* Si le pointeur vaut NULL, cela signifie que la factory associée
       * n'existe pas: dans ce cas là, on envoie une exception
       */
      throw NoteException(QObject::tr("Type de note pour ") + f.fileName() + QObject::tr(" non supporté."));
    }
  }
  else {
    throw NoteException(QObject::tr("Unable to load the file ") + f.fileName());
  }
}
예제 #2
0
/**
 * @brief HtmlExportStrategy::exportNote
 * @param n
 * @param header
 * @return
 */
QString HtmlExportStrategy::exportNote(Note *n, bool header){
  QString exp;
  QTextStream flux(&exp);
  flux.setCodec("UTF-8");
  //header
  flux<<"<html>"<<endl<<"<head>"<<endl<<"</head>"<<endl<<"<body>"<<endl;
  if (n == NULL) {
    return "";
  }
  if (dynamic_cast<Article*>(n) != NULL) {
    flux<<HtmlExportStrategy::exportNoteArt(dynamic_cast<Article*>(n));
  }
  else if (dynamic_cast<Image*>(n) != NULL) {
    flux<<HtmlExportStrategy::exportNoteIm(dynamic_cast<Image*>(n));
  }
  else if (dynamic_cast<Audio*>(n) != NULL) {
    flux<<HtmlExportStrategy::exportNoteAud(dynamic_cast<Audio*>(n));
  }
  else if (dynamic_cast<Video*>(n) != NULL) {
    flux<<HtmlExportStrategy::exportNoteVid(dynamic_cast<Video*>(n));
  }
  else if (dynamic_cast<Document*>(n) != NULL) {
    flux<<HtmlExportStrategy::exportNoteDoc(dynamic_cast<Document*>(n));
  }
  else
      throw NoteException("erreur : le type n'est pas conforme");
  //footer
  flux<<"</body>"<<endl<<"</html>"<<endl;
  return exp;
}
예제 #3
0
/**
 * @brief Article::load
 */
void Article::load()
{
    //1er cas : si on a déjà chargé les modifications faites sur le fichier, on ne le recharge pas.
    if (loaded)
        return;
    //2e cas:
    else {
        QFile fichier(NotesManager::getInstance()->getFilename(id));
        //2e cas a: on vérifie que le fichier existe
        if (fichier.open(QIODevice::ReadOnly | QIODevice::Text)){
            QTextStream flux(&fichier);
            //On enlève la première ligne : type de la note
            flux.readLine();
            //Lecture du titre de la note
            title = flux.readLine();
            //Lecture de la description de la note
            content = flux.readAll();

            loaded = true;
            fichier.close();
        }
        //2e cas b
        else {
            NoteException("Erreur : tentative de charger un fichier non crée");
        }
    }
}
예제 #4
0
/**
 * Ajoute un tag à la liste des tags gérés par
 * le tag manager, à partir de son nom
 */
void TagManager::add(QString tagName)  throw(NoteException)
{
  if (tags.contains(tagName)) {
    throw NoteException(QObject::tr("Le tag de nom ") + tagName + QObject::tr(" existe déjà"));
  }
  tags[tagName] = new Tag(tagName);
}
예제 #5
0
파일: Note.cpp 프로젝트: Timost/LO21
Note getWorstValidatoryNote(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
    std::vector<Note> test=getValidatoryNotes(begin,end);
    if(test.size()==0)
    {
        throw NoteException("Erreur getWorstValidatoryNote(...,...), il n'y a pas de notes validantes dans ce tableau");
    }
    return getWorstNote(begin,end);
}
예제 #6
0
/**
 * Ajoute une note à la liste des notes gérées
 * par le NotesManager
 * @param type Type de la note
 */
Note* NotesManager::add(QString type)
{
  if (!factories.contains(type)) {
    throw NoteException(QObject::tr("Wrong note type givento NotesManager::add"));
  }
  Note *n = factories[type]->newNote("");
  notes[n->getId()] = n;
  return n;
}
예제 #7
0
파일: Note.cpp 프로젝트: Timost/LO21
Note StringToNote(const QString& str){//renvoie une référence vers la catégorie si elle existe, exception sinon.
   TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();

   if(tNote.alreadyExist(str))
   {
       return tNote.getElement(str);
   }
   else
   {
       throw NoteException("Erreur la note "+str.toStdString()+" n'existe pas.");
   }
}
예제 #8
0
파일: Note.cpp 프로젝트: Timost/LO21
Note getBestNote(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
    if(begin==end)
    {
        throw NoteException("Erreur getBestNote() les itérateurs sont egaux, vous iterez probablement sur un tableau vide");
    }
    Note max = *begin;
    begin++;
    for(std::vector<Note>::iterator itNote=begin;itNote != end;itNote++)
    {
        if(itNote->getRang()<max.getRang())
        {
            max=*itNote;
        }
    }
    return max;
}
예제 #9
0
파일: Video.cpp 프로젝트: sam101/LO21_Notes
/**
 * Sauvegarde les informations de la video
 * dans son fichier
 */
void Video::save()
{
  //TODO: Factoriser avec Video::save/Audio::save ?
  QFile f(NotesManager::getInstance()->getFilename(id));

  if (!f.open(QIODevice::WriteOnly | QIODevice::Text))
    throw NoteException(QObject::tr("Unable to load the file ") + f.fileName() + QObject::tr(" for saving"));
  //on déclare le flux pour écrire dans le fichier
  QTextStream stream(&f);
  //Type de la note
  stream << "video" << endl;
  //Informations sur la note
  stream << title << endl;
  stream << path << endl;
  stream << description;
  modified = false;
  f.close();
}
예제 #10
0
파일: Note.cpp 프로젝트: Timost/LO21
Note getWorstNote(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
    if(begin==end)
    {
        throw NoteException("Erreur getBestNote() les itérateurs sont egaux, vous iterez probablement sur un tableau vide");
    }
    Note min = *begin;
    begin++;
    bool foundDeterminantNote=false;//les notes non déterminantes ne comptes pas.
    for(std::vector<Note>::iterator itNote=begin;itNote != end;itNote++)
    {
        if((!foundDeterminantNote)&&(itNote->getRang()>0))
        {
            foundDeterminantNote=true;
            min=*itNote;
        }
        if((foundDeterminantNote)&&(itNote->getRang()>min.getRang()))
        {
            min=*itNote;
        }
    }
    return min;
}
예제 #11
0
/**
 * @brief Article::save
 */
void Article::save(){
    //1er cas si le fichier a déjà été sauvegardé, on ne le sauvegarde pas une nouvelle fois
    if (!modified)
        return;
    //2e cas
    else {
         QFile fichier (NotesManager::getInstance()->getFilename(id));
        //Si le fichier n'est pas encore crée, il le crée
        if (fichier.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QTextStream flux(&fichier);
            flux.setCodec("UTF-8");
            //Type de la note
            flux << "article" << endl;
            //Informations sur la note
            flux << title << endl;
            flux << content << endl;
            modified = false;
            fichier.close();
        }
        else {
            throw NoteException(QObject::tr("Unable to load the file ") + fichier.fileName() + QObject::tr(" for saving"));
        }
    }
}
예제 #12
0
파일: Note.cpp 프로젝트: Timost/LO21
Note::Note(std::string n, std::string d, unsigned int r, unsigned int e)
{
    if(e>2)
    {
        throw NoteException("Erreur : le dernier parametres doit etre compris entre 0 et 2 inclus :(0:pas eliminatoire,1 eliminatoire, 2 non determinante)");
    }
   TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
   if(!tNote.alreadyExist(n))
    {
       if(tNote.size()>0)
       {
          // qDebug()<<"taille  : "<<tNote.size();
            if((getEliminatoryNotes().size()>0)&&(getBestEliminatoryNote().getRang()<r)&&(e!=1))
            {
                throw NoteException("Erreur : cette Note "+n+" doit etre eliminatoire etant donne son rang!");
            }
            if((getValidatoryNotes().size()>0)&&(getWorstValidatoryNote().getRang()>r)&&(e==1))
            {
                throw NoteException("Erreur : cette Note "+n+" ne doit pas etre eliminatoire etant donne son rang!");
            }
            if((e==2)&&(r!=0))
            {
                throw NoteException("Erreur : Une note non determinante doit etre de rang 0!("+n+")");
            }
            if((e!=2)&&(r==0))
            {
                throw NoteException("Erreur : Une note determinante doit etre de rang > 0!("+n+")");
            }
       }
        note=QString::fromStdString(n);
        description=QString::fromStdString(d);
        rang=r;
        eliminatoire=e;

        tNote.New(*this);
    }
    else
    {
        throw NoteException("Erreur : la note "+n+" existe deja !");
    }
}