Skip to content

Commit

Permalink
Channel finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimazm committed Jul 8, 2022
1 parent 9282480 commit 313ff22
Show file tree
Hide file tree
Showing 45 changed files with 1,545 additions and 106 deletions.
3 changes: 3 additions & 0 deletions SocialMedia/SocialMedia.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CONFIG += c++17

SOURCES += \
add_admin.cpp \
add_member.cpp \
channel.cpp \
chat.cpp \
creat_channele.cpp \
Expand All @@ -28,6 +29,7 @@ SOURCES += \

HEADERS += \
add_admin.h \
add_member.h \
channel.h \
chat.h \
creat_channele.h \
Expand All @@ -45,6 +47,7 @@ HEADERS += \

FORMS += \
add_admin.ui \
add_member.ui \
channel.ui \
creat_channele.ui \
darugram.ui \
Expand Down
118 changes: 118 additions & 0 deletions SocialMedia/add_member.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include "add_member.h"
#include "ui_add_member.h"
#include<iostream>
#include<QJsonArray>
#include<QJsonDocument>
#include<QJsonObject>
#include<QFile>
#include<QMessageBox>
#include<QPushButton>
#include<QListWidget>

void Add_Member::on_btn_Clicked()
{
QPushButton* buttonSender = qobject_cast<QPushButton*>(sender()); // retrieve the button you have clicked
QString buttonText = buttonSender->text(); // retrive the text from the button clicked
QJsonObject All_Channel;
QFile F_R_Channel("All_Channel.json");
if(F_R_Channel.open(QIODevice::ReadOnly))
{
QByteArray a = F_R_Channel.readAll();
QJsonDocument b = QJsonDocument::fromJson(a);
All_Channel = b.object();
F_R_Channel.close();
}
QJsonObject This_Channel = All_Channel[Chat_name].toObject();
QJsonArray members = This_Channel["Members"].toArray();
members.append(buttonText);
This_Channel["Members"] = members;
All_Channel[Chat_name] = This_Channel;
QFile F_W_Channel("All_Channel.json");
if(F_W_Channel.open(QIODevice::WriteOnly))
{
QJsonDocument Channel_file(All_Channel);
F_W_Channel.write(Channel_file.toJson());
F_W_Channel.close();
}
QJsonObject All_User;
QFile F_R_Users("All_User.json");
if(F_R_Users.open(QIODevice::ReadOnly))
{
QByteArray a = F_R_Users.readAll();
QJsonDocument b = QJsonDocument::fromJson(a);
All_User = b.object();
F_R_Users.close();
}
QJsonObject This_User = All_User[buttonText].toObject();
QJsonArray User_chats = This_User["Chats"].toArray();
User_chats.append(this->Chat_name);
This_User["Chats"] = User_chats;
All_User[buttonText] = This_User;
QJsonDocument All_User_File(All_User);
QFile F_W_Users("All_User.json");
if(F_W_Users.open(QIODevice::WriteOnly))
{
F_W_Users.write(All_User_File.toJson());
F_W_Users.close();
}
QMessageBox::information(this,"operation Succesful",buttonText+" Added");
this->destroy();
}

Add_Member::Add_Member(QString Current_user,QString Chat_Page,QWidget *parent) :
QDialog(parent),
ui(new Ui::Add_Member)
{
ui->setupUi(this);
QFile F_R_User("All_User.json");
this->Chat_name = Chat_Page;
QJsonObject All_User;
if(F_R_User.open(QIODevice::ReadOnly))
{
QByteArray a = F_R_User.readAll();
QJsonDocument b = QJsonDocument::fromJson(a);
All_User = b.object();
F_R_User.close();
}
QJsonObject All_Channel;
QFile F_R_Channel("All_Channel.json");
if(F_R_Channel.open(QIODevice::ReadOnly))
{
QByteArray a = F_R_Channel.readAll();
QJsonDocument b = QJsonDocument::fromJson(a);
All_Channel = b.object();
F_R_Channel.close();
}
QJsonObject This_User = All_User[Current_user].toObject();
QJsonObject This_Channel = All_Channel[Chat_Page].toObject();
QJsonArray contacts = This_User["Contacts"].toArray();
QJsonArray Members = This_Channel["Members"].toArray();
QJsonArray Show;
for(int i = 0 ;i<contacts.size();i++)
{
int state = 1;
for(int j=0;j<Members.size();j++)
{
if(contacts[i]==Members[j])
{
state = 0;
break;
}
}
if(state)
Show.append(contacts[i]);
}
for(int i = 0; i<Show.size();i++)
{
QPushButton* btn = new QPushButton(Show[i].toString());
connect(btn, SIGNAL(clicked()), this, SLOT(on_btn_Clicked()));
QListWidgetItem *item = new QListWidgetItem(ui->listWidget);
ui->listWidget->addItem(item);
ui->listWidget->setItemWidget(item, btn);
}
}

Add_Member::~Add_Member()
{
delete ui;
}
25 changes: 25 additions & 0 deletions SocialMedia/add_member.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef ADD_MEMBER_H
#define ADD_MEMBER_H

#include <QDialog>

namespace Ui {
class Add_Member;
}

class Add_Member : public QDialog
{
Q_OBJECT

public slots:
void on_btn_Clicked();
public:
explicit Add_Member(QString Current_user,QString Chat_Page,QWidget *parent = nullptr);
~Add_Member();

private:
Ui::Add_Member *ui;
QString Chat_name;
};

#endif // ADD_MEMBER_H
29 changes: 29 additions & 0 deletions SocialMedia/add_member.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Add_Member</class>
<widget class="QDialog" name="Add_Member">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>298</width>
<height>588</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>5</x>
<y>10</y>
<width>291</width>
<height>571</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
16 changes: 16 additions & 0 deletions SocialMedia/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include<QMessageBox>
#include"deletemember.h"
#include"add_admin.h"
#include"add_member.h"
Channel::Channel(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Channel)
Expand Down Expand Up @@ -52,6 +53,7 @@ Channel::Channel(QString Chat_page_name, User* Current_User,QWidget *parent) :
{
ui->Add_admin_btn->hide();
ui->Delete_member_btn->hide();
ui->Add_Member->hide();
}
}
else
Expand Down Expand Up @@ -198,3 +200,17 @@ void Channel::on_Delete_member_btn_clicked()
deletm->show();
}


void Channel::on_Add_Member_clicked()
{
Add_Member* new_member = new Add_Member(Current_User->getID(),this->getChannelName(),this);
new_member->show();
}


void Channel::on_Refresh_clicked()
{
ui->listWidget->clear();
this->Updating_page(this->getChannelName());
}

4 changes: 4 additions & 0 deletions SocialMedia/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ private slots:

void on_Delete_member_btn_clicked();

void on_Add_Member_clicked();

void on_Refresh_clicked();

private:
User creator;
QVector<User> admins;
Expand Down
29 changes: 21 additions & 8 deletions SocialMedia/channel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<widget class="QPushButton" name="Add_admin_btn">
<property name="geometry">
<rect>
<x>30</x>
<x>40</x>
<y>10</y>
<width>171</width>
<width>131</width>
<height>51</height>
</rect>
</property>
Expand All @@ -40,9 +40,9 @@
<widget class="QPushButton" name="Delete_member_btn">
<property name="geometry">
<rect>
<x>410</x>
<x>480</x>
<y>10</y>
<width>171</width>
<width>141</width>
<height>51</height>
</rect>
</property>
Expand All @@ -53,9 +53,9 @@
<widget class="QPushButton" name="See_mem_btn">
<property name="geometry">
<rect>
<x>220</x>
<x>330</x>
<y>10</y>
<width>171</width>
<width>141</width>
<height>51</height>
</rect>
</property>
Expand Down Expand Up @@ -89,16 +89,29 @@
<widget class="QPushButton" name="Add_Member">
<property name="geometry">
<rect>
<x>600</x>
<x>630</x>
<y>10</y>
<width>171</width>
<width>141</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>Add_Member</string>
</property>
</widget>
<widget class="QPushButton" name="Refresh">
<property name="geometry">
<rect>
<x>180</x>
<y>10</y>
<width>141</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down
23 changes: 23 additions & 0 deletions SocialMedia/pv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,26 @@ void Pv::on_Send_btn_clicked()

}


void Pv::on_refresh_clicked()
{

QJsonObject All_Messages;
QFile F_R_Messages("All_Message.json");
if(F_R_Messages.open(QIODevice::ReadOnly))
{
QByteArray a = F_R_Messages.readAll();
QJsonDocument b = QJsonDocument::fromJson(a);
All_Messages = b.object();
F_R_Messages.close();
}
QJsonObject This_Chat;
This_Chat=All_Messages[this->get_Chat_page_name()].toObject();
QJsonArray messages = This_Chat["Messages"].toArray();
ui->listWidget->clear();
for(int i = 0;i<messages.size();i++)
{
ui->listWidget->addItem(messages[i].toString());
}
}

2 changes: 2 additions & 0 deletions SocialMedia/pv.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Pv : public QMainWindow , public Chat
private slots:
void on_Send_btn_clicked();

void on_refresh_clicked();

private:
Ui::Pv *ui;
};
Expand Down
15 changes: 14 additions & 1 deletion SocialMedia/pv.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<widget class="QPushButton" name="Profile_btn">
<property name="geometry">
<rect>
<x>470</x>
<x>100</x>
<y>10</y>
<width>211</width>
<height>24</height>
Expand Down Expand Up @@ -73,6 +73,19 @@
<string>Send</string>
</property>
</widget>
<widget class="QPushButton" name="refresh">
<property name="geometry">
<rect>
<x>414</x>
<y>10</y>
<width>281</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 313ff22

Please sign in to comment.