Example #1
0
QList<HistoryItem> HistoryEngine::loadHistoryMessage(const TreeModelItem &item, int n, const QDateTime &date_last)
{
  int num=0;
  QVector<HistoryItem> vector(n);
  QDir dir = accountDir(item);
  QStringList files = fileNames(item);
  if (files.size()<1)
    return QList<HistoryItem>();
  for (int month=files.size()==1?1:2;month>0;month--)
  {
    QFile file(dir.filePath(files[files.size()-month]));
    if (file.open(QIODevice::ReadOnly))
    {
      QDataStream in(&file);
      HistoryItem history;
      while (!file.atEnd())
      {
        in >> history.m_time >> history.m_type >> history.m_in >> history.m_message;
        if (history.m_time < date_last)
        {
          vector[num%n] = history;
          num++;
        }
      }
    }
  }
Example #2
0
 void flushFile( const std::string& account, const std::string& tag, const std::string& fileName ){
   boost::filesystem::path accountDir( account );
   if( !boost::filesystem::exists( accountDir ) ) boost::filesystem::create_directory( accountDir );
   boost::filesystem::path tagDir( tag.c_str() );
   tagDir = accountDir / tagDir;
   if( !boost::filesystem::exists( tagDir ) ) boost::filesystem::create_directory( tagDir );
   boost::filesystem::path sourceFilePath( fileName );
   boost::filesystem::path destFilePath = tagDir / sourceFilePath.leaf();
   if( boost::filesystem::exists(destFilePath) ) boost::filesystem::remove(destFilePath);
   boost::filesystem::copy_file( sourceFilePath, destFilePath  );
 }
Example #3
0
bool HistoryEngine::saveSystemMessage(const HistoryItem &item)
{
  //QString line = item.m_time.toString("|yyyy-MM-ddThh:mm:ss|");
  //line+=QString().setNum(item.m_type)+"|"+hex(item.m_user.m_item_name)+"|"+QString(item.m_message).replace("\\","\\\\").replace("\n","\\n");
  QFile file(accountDir(item.m_user).filePath("sys."+item.m_time.toString(".yyyyMM")+".log"));
  if (!file.open(QIODevice::Append | QIODevice::WriteOnly))// | QIODevice::Text))
    return false;
  QDataStream out(&file);
  out << item.m_time << item.m_type << item.m_user.m_item_name << item.m_message;
  /*QTextStream out(&file);
  out.setAutoDetectUnicode(false);
  out.setCodec("UTF-8");
  out << line;*/
  return true;
}
Example #4
0
bool HistoryEngine::saveHistoryMessage(const HistoryItem &item)
{
  /*QString line = item.m_time.toString("|yyyy-MM-ddThh:mm:ss|");
  line+=QString().setNum(item.m_type)+(item.m_in?"|in|":"|out|")+QString(item.m_message).replace("\\","\\\\").replace("\n","\\n")+"\n";
  QFile file(accountDir(item.m_user).filePath(fileName(item)));
  QFileInfo info(file);*/
  QFile file(accountDir(item.m_user).filePath(fileName(item)));
  if (!file.open(QIODevice::Append | QIODevice::WriteOnly))// | QIODevice::Text))
    return false;
  QDataStream out(&file);
  out << item.m_time << item.m_type << item.m_in << item.m_message;
  /*QTextStream out(&file);
  out.setAutoDetectUnicode(false);
  out.setCodec("UTF-8");
  out << line;*/
  return true;
}