📄 mainwindow.cpp
字号:
// Protected by the GNU General Public License#include "mainwindow.h"MainWindow::MainWindow (QWidget *parent) : QMainWindow(parent){ QString home = getenv( "HOME" ); QString pathsmsDir = home + "/.smsbox"; QDir dir(pathsmsDir); if(!dir.exists()) { dir.mkdir( pathsmsDir, TRUE); } if(dir.exists()) { dir.mkdir(pathsmsDir+"/.tmp"); dir.mkdir(pathsmsDir+"/dir"); dir.mkdir(pathsmsDir+"/dir/inbox"); dir.mkdir(pathsmsDir+"/dir/outbox"); dir.mkdir(pathsmsDir+"/dir/sentsms"); dir.mkdir(pathsmsDir+"/dir/trash"); dir.mkdir(pathsmsDir+"/sms"); } resize(240,300); setCaption(tr("SMS")); QToolBar *toolbar = new QToolBar(this); setToolBarsMovable(false); addToolBar(toolbar); QWidget *centralWidget = new QWidget(this); setCentralWidget(centralWidget); QAction *newSMS = new QAction(tr("Write newsms"), QIconSet(QPixmap("newmail.png")), 0, 0, this); newSMS->addTo(toolbar); connect(newSMS, SIGNAL(activated()), this, SLOT(newMessage())); checkSMS = new QAction(tr("Check SMS"), QIconSet(QPixmap("checkmail.png")), 0, 0, this); connect(checkSMS, SIGNAL(activated()), this, SLOT(getSMS())); checkSMS->addTo(toolbar); checkSMS->setEnabled(true); stop = new QAction(tr("Stop"), QIconSet(QPixmap("stop.png")), 0, 0, this); connect(stop, SIGNAL(activated()), this, SLOT(cancel())); stop->addTo(toolbar); stop->setEnabled(false); QGridLayout *layout = new QGridLayout(centralWidget); smsList = new QListView(centralWidget); smsList->addColumn(tr("No"), 20); smsList->addColumn(tr("Sender"), 105); smsList->addColumn(tr("Content"), 105); smsList->setAllColumnsShowFocus(true); connect(smsList, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(smsSelected(QListViewItem *))); QListViewItem *inbox = new QListViewItem(smsList); inbox->setPixmap(0,QPixmap("inbox.png")); inbox->setText(0,tr("Inbox")); layout->addWidget(smsList,0,0); recvsms = new RecvSMS(); connect(recvsms, SIGNAL(newMessage(const QString &)), this, SLOT(addSMS(const QString &))); connect(recvsms, SIGNAL(updateStatus(const QString &)), this, SLOT(setStatusText(const QString &))); connect(recvsms, SIGNAL(errorOccurred(int)), this, SLOT(recvError(int))); getStuff();}void MainWindow::smsSelected(QListViewItem *item){ ViewSMS *viewSMS = new ViewSMS(SMSs[(item->text(0).toInt()) - 1], item->text(0)); viewSMS->showMaximized(); viewSMS->show(); connect(viewSMS, SIGNAL(smsDeleted()), this, SLOT(getStuff()));}void MainWindow::getStuff(){ smsList->clear(); QString home = getenv( "HOME" ); QDir d(home + "/.smsbox/dir/inbox"); QStringList contents = d.entryList("*", QDir::Files, QDir::Name); QString sms; for (QStringList::Iterator it = contents.begin(); it != contents.end(); it++) { sms = ""; if ((*it).toUInt()) { QFile f( home + "/.smsbox/dir/inbox/" + *it ); if (!f.open(IO_ReadOnly)) break; QTextStream t(&f); while (!t.atEnd()) sms += t.readLine() + "\n"; SMSParser p(sms); SMS esms = p.parsed(); SMSs[(*it).toUInt()] = esms; QListViewItem *item = new QListViewItem(smsList); item->setText(0,*it); item->setText(1,esms.from()); item->setText(2,esms.body()); } }}void MainWindow::newMessage(){ Composer *composer = new Composer(); composer->showMaximized(); composer->show();}void MainWindow::getSMS(){ setStatusText(tr("Looking up...")); printf("Start Thread\n"); checkSMS->setEnabled(false); recvsms->go(); stop->setEnabled(true);}void MainWindow::recvError(int error){ QMessageBox::warning(this, tr("Unknown Error"), tr("An unknown error occoured."), tr("Ok")); stop->setEnabled(false); recvsms->stop(); checkSMS->setEnabled(true);}void MainWindow::setStatusText(const QString &msg){ //Global::statusMessage(msg);}void MainWindow::addSMS(const QString &sms){ QString home = getenv( "HOME" ); QDir d(home + "/.smsbox/dir/inbox"); QStringList contents = d.entryList("*", QDir::Files, QDir::Name); int num = 1; for (QStringList::Iterator i = contents.begin(); i != contents.end(); i++) { if ((*i).toInt() >= num) num = (*i).toInt() + 1; } QString location = "/.smsbox/dir/inbox/%1"; QFile f(home + location.arg(num)); if (!f.open(IO_WriteOnly|IO_Append)) { QMessageBox::warning(this, tr("Error"), tr("Can't write sms to disk.\nMaybe you haven't enough diskspace left?", tr("Ok"))); return; } QTextStream t(&f); t << sms; f.close(); cout << sms << endl; printf("Saved\n"); getStuff();}void MainWindow::cancel(){ printf("Cancel Thread\n"); checkSMS->setEnabled(true); recvsms->stop(); stop->setEnabled(false);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -