MonitorWidget::MonitorWidget(QTabWidget* parent):QTabWidget(parent) { // setTabShape(QTabWidget::Triangular); // setFocusPolicy(Qt::NoFocus); setStyleSheet("QTabBar::tab{background: #D1EEEE;min-width:135;min-height:40;} \ QTabBar::tab:hover{background: white} \ QTabBar::tab:selected{background:lightseagreen;border-color: #EE0000}"); widget1 = new MoniFileWidget; widget1->setFocusPolicy(Qt::NoFocus); widget1->setFrameShape(QListWidget::NoFrame);//无边框 widget1->setStyleSheet("QListWidget::item:selected{background-color:#C1FFC1;color:black;} "); //开始或暂停监控 connect(widget1,SIGNAL(StartSig(QString,int)),this,SLOT(StartMonitorSlot(QString,int))); InotifyFilter itmp; string s,sname; int b; ifstream in("./etc/gaoyuan/record.txt"); //监控文件 while(!in.eof()) { in>>s; if(in.fail()) break; cout<<s<<endl; sname = s; widget1->SetSelectedFile(QString::fromStdString(s)); //以下读取过滤 in>>s; itmp.startdate = s; in>>s; itmp.enddate = s; in>>s; itmp.suffix = s; in>>s; itmp.startsize = s; in>>s; itmp.endsize = s; in>>b; itmp.isfolder = b; in>>b; itmp.isfile = b; //读取起始监控日期 in>>s; cout<<s<<endl; itmp.idate = s; widget1->AddListItem(QString::fromStdString(s)); //加入监控列表 fnotify.InotifyListAdd(sname,itmp); } in.close(); addMonitorButton = new QPushButton(tr("添加监控项")); addMonitorButton->setFocusPolicy(Qt::NoFocus); addMonitorButton->setStyleSheet("background-color:white"); connect(addMonitorButton,SIGNAL(clicked()),this,SLOT(ShowAddMonitorSlot())); // widget2 = new QWidget; widget3 = new VersionWidget; widget3->setFocusPolicy(Qt::NoFocus); widget3->setFrameShape(QListWidget::NoFrame);//无边框 widget3->setStyleSheet("QListWidget::item:selected{background-color:#C1FFC1;color:black;} "); connect(&fnotify,SIGNAL(VersionAlterSig(string,string,string)),widget3,SLOT(VersionAlterSlot(string,string,string))); setFocusPolicy(Qt::NoFocus); addTab(widget1,tr("监控列表")); addTab(addMonitorButton,tr("添加监控")); addTab(widget3,tr("版本回退")); } //add monitor void MonitorWidget::ShowAddMonitorSlot() { AddMonitorWidget* w = new AddMonitorWidget; connect(w,SIGNAL(AddMonitorItemSig(string,InotifyFilter)),this,SLOT(AddMonitorItemSlot(string,InotifyFilter))); w->resize(800,600); w->show(); }
void FInotify::InotifyEvent(struct inotify_event* i) { map<int,string>::iterator it; it = inotifyRunlist.find(i->wd); if(it == inotifyRunlist.end()) return; string file; file = it->second + "/" + i->name; //过滤 //如果是隐藏文件 string tmpname = i->name; if(tmpname[0] == '.' || tmpname == "4913" || tmpname[tmpname.size()-1]=='~') return; //旧文件 string oldfile = "./etc/lyh" + getRoadFolder(it->second) + "/" + tmpname; //命令 string command; //更新变更记录 ofstream out; out.open("./etc/lyh/alter.txt",ios::app); //时间秒数 time_t t; time(&t); //时间转字符串 char nowtime[20]; sprintf(nowtime,"%ld",t); int ret; string type,dsc,dst; if( (i->mask & IN_MODIFY) && (i->len > 0 ) ) { cout<<"修改文件:"<<file<<endl; command = "cp " + oldfile + " " + "./etc/lyh/history/" + nowtime; ret = system(command.c_str()); command = "cp " + file + " " + oldfile; ret = system(command.c_str()); type = "modify"; dsc = file; dst = nowtime; out<<type<<" "<<dsc<<" "<<dst<<endl; emit(VersionAlterSig(type,dsc,dst)); // out<<"modify "<<file<<" "<<nowtime<<endl; } if((i->mask & IN_CREATE) && (i->len > 0 )) { if(i->mask & IN_ISDIR) cout<<"创建目录:"<<file<<endl; else cout<<"创建文件:"<<file<<endl; command = "cp " + file + " " + oldfile; ret = system(command.c_str()); type = "add"; dsc = it->second; dst = file; out<<type<<" "<<dsc<<" "<<dst<<endl; emit(VersionAlterSig(type,dsc,dst)); // out<<"add "<<it->second<<" "<<file<<endl; } if((i->mask & IN_DELETE) && (i->len > 0)) { if(i->mask & IN_ISDIR) cout<<"删除目录:"<<file<<endl; else cout<<"删除文件:"<<file<<endl; command = "mv " + oldfile + " " + "./etc/lyh/recycle/" + nowtime; ret = system(command.c_str()); type = "delete"; dsc = file; dst = nowtime; out<<type<<" "<<dsc<<" "<<dst<<endl; emit(VersionAlterSig(type,dsc,dst)); // out<<"delete "<<file<<" "<<nowtime<<endl; } out.close(); }